Change char-set->regexp to use string builder.
authorChris Hanson <org/chris-hanson/cph>
Sun, 30 Apr 2017 03:28:44 +0000 (20:28 -0700)
committerChris Hanson <org/chris-hanson/cph>
Sun, 30 Apr 2017 03:28:44 +0000 (20:28 -0700)
src/runtime/regexp.scm

index 468267752604c69393ceab81ac3f5ef98a2470a6..3f3cb6d1eef512203b9a0fe84ba5b81172e6643f 100644 (file)
@@ -195,22 +195,19 @@ USA.
                           (loop (cdr ranges)
                                 (fix:+ n (if (pair? (car ranges)) 3 1)))
                           n))))
-               (let ((s (make-legacy-string n)))
-                 (string-set! s 0 #\[)
-                 (let loop ((ranges ranges) (i 1))
+               (let ((builder (string-builder)))
+                 (builder #\[)
+                 (let loop ((ranges ranges))
                    (if (pair? ranges)
-                       (loop (cdr ranges)
-                             (let ((range (car ranges)))
-                               (if (pair? range)
-                                   (begin
-                                     (string-set! s i (car range))
-                                     (string-set! s (fix:+ i 1) #\-)
-                                     (string-set! s (fix:+ i 2) (cdr range))
-                                     (fix:+ i 3))
-                                   (begin
-                                     (string-set! s i range)
-                                     (fix:+ i 1)))))
-                       (string-set! s i #\])))
-                 s)))
+                       (let ((range (car ranges)))
+                         (if (pair? range)
+                             (begin
+                               (builder (car range))
+                               (builder #\-)
+                               (builder (cdr range)))
+                             (builder range)))
+                       (loop (cdr ranges))))
+                 (builder #\])
+                 (builder))))
            (re-quote-string (string (car chars))))
        "")))
\ No newline at end of file