From c5ea8c032c8da4ba74e86cba96159bba0cf0ed04 Mon Sep 17 00:00:00 2001
From: ben <types@ccs.neu.edu>
Date: Tue, 8 Dec 2015 03:23:29 -0500
Subject: [PATCH] [regexp] linear-time group unpacking, hooray for mutability

---
 regexp.rkt | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/regexp.rkt b/regexp.rkt
index 2a7ffe7..1f974a2 100644
--- a/regexp.rkt
+++ b/regexp.rkt
@@ -45,15 +45,15 @@
   (syntax-parser
    [(f pat-stx arg* ...)
     #:with num-groups (count-groups #'pat-stx #:src #'f)
-    #:with ((index* . group-id*) ...)
-           #`#,(for/list ([i (in-range (syntax-e #'num-groups))])
-                 (cons i (format-id #'f "group-~a" i)))
-    ;; Chaining list-ref?
-    #'(let ([m (regexp-match pat-stx arg* ...)])
-        (if m
-          (let ([group-id* (or (list-ref m index*) (error 'regexp-match! "Internal error, try Racket's `regexp-match`"))] ...)
-            (list (car m) group-id* ...))
-          m))]
+    #:with (index* ...) #`#,(for/list ([i (in-range (syntax-e #'num-groups))]) i)
+    #'(let ([maybe-match (regexp-match pat-stx arg* ...)])
+        (if maybe-match
+          (let ([m : (Listof (Option String)) maybe-match])
+            (list (car maybe-match)
+                  (begin (set! m (cdr m))
+                         (or (car m) (error 'regexp-match! (format "Internal error at result index ~a, try Racket's regexp-match" index*))))
+                  ...))
+          #f))]
    [(f arg* ...)
     (syntax/loc #'f (regexp-match arg* ...))]))