From c43ce00421e0b2688add6b89d94d2bb43313824b Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sat, 29 Apr 2017 20:28:44 -0700 Subject: [PATCH] Change char-set->regexp to use string builder. --- src/runtime/regexp.scm | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/runtime/regexp.scm b/src/runtime/regexp.scm index 468267752..3f3cb6d1e 100644 --- a/src/runtime/regexp.scm +++ b/src/runtime/regexp.scm @@ -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 -- 2.25.1