From: Chris Hanson Date: Thu, 23 Feb 2017 06:10:36 +0000 (-0800) Subject: Eliminate reverse-string altogether. It's meaningless in Unicode. X-Git-Tag: mit-scheme-pucked-9.2.12~220^2~12 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=5884e77edaff1745d267b8a65a0b17f86996794b;p=mit-scheme.git Eliminate reverse-string altogether. It's meaningless in Unicode. --- diff --git a/doc/ref-manual/strings.texi b/doc/ref-manual/strings.texi index c9274b07d..d4b442d6a 100644 --- a/doc/ref-manual/strings.texi +++ b/doc/ref-manual/strings.texi @@ -467,18 +467,6 @@ Returns a newly allocated string containing the same characters as replaced by @var{char2}. @end deffn -@deffn procedure reverse-string string -Returns a newly allocated string with the same characters as -@var{string} but in the reverse order. - -@example -@group -(reverse-string "foo bar baz") @result{} "zab rab oof" -(reverse-string (string-slice "foo bar baz" 4 7)) @result{} "rab" -@end group -@end example -@end deffn - @node Searching Strings, Matching Strings, Strings, Strings @section Searching Strings @cindex searching, of string diff --git a/src/compiler/machines/C/stackify.scm b/src/compiler/machines/C/stackify.scm index 85d200544..dc29a7698 100644 --- a/src/compiler/machines/C/stackify.scm +++ b/src/compiler/machines/C/stackify.scm @@ -502,10 +502,12 @@ USA. prog)) ((bit-string? obj) (build/string stackify-opcode/push-bit-string - (reverse-string - (number->string - (bit-string->unsigned-integer obj) - 16)) + (list->string + (reverse + (string->list + (number->string + (bit-string->unsigned-integer obj) + 16)))) (build/push-nat (bit-string-length obj) prog))) ((scode/primitive-procedure? obj) (let ((arity (primitive-procedure-arity obj)) diff --git a/src/edwin/edwin.pkg b/src/edwin/edwin.pkg index f1b6090c2..92d17a05e 100644 --- a/src/edwin/edwin.pkg +++ b/src/edwin/edwin.pkg @@ -166,10 +166,6 @@ USA. make-string make-vector-8b random-byte-vector - reverse-string - reverse-string! - reverse-substring - reverse-substring! set-string-length! string string->list diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 7cfce3571..a7a8411dd 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -1031,7 +1031,6 @@ USA. (substring string-copy) list->string make-string - reverse-string string string* string->list diff --git a/src/runtime/string.scm b/src/runtime/string.scm index cde00ab1b..350ec683d 100644 --- a/src/runtime/string.scm +++ b/src/runtime/string.scm @@ -296,7 +296,7 @@ USA. (define (%bm-substring-search-backward text tstart tend pattern pstart pend) (let ((m (fix:- pend pstart)) (pend-1 (fix:- pend 1)) - (rpattern (reverse-string (string-slice pattern pstart pend)))) + (rpattern (reverse-pattern pattern pstart pend))) (let ((tstart+m (fix:+ tstart m)) (lambda* (compute-last-occurrence-function rpattern 0 m)) (gamma @@ -352,9 +352,9 @@ USA. (define (compute-good-suffix-function pattern pstart pend gamma0) (let ((m (fix:- pend pstart))) (let ((pi - (compute-prefix-function - (reverse-string (string-slice pattern pstart pend)) - 0 m)) + (compute-prefix-function (reverse-pattern pattern pstart pend) + 0 + m)) (gamma (make-vector m gamma0)) (m-1 (fix:- m 1))) (do ((l 0 (fix:+ l 1))) @@ -390,6 +390,13 @@ USA. (vector-set! pi q k) (outer k (fix:+ q 1))))) pi)) + +(define (reverse-pattern pattern pstart pend) + (let ((builder (string-builder))) + (do ((i (fix:- pend 1) (fix:- i 1))) + ((not (fix:>= i pstart))) + (builder (string-ref pattern i))) + (builder))) ;;;; Guarantors ;; diff --git a/src/runtime/ustring.scm b/src/runtime/ustring.scm index b8c2590e3..1f34cc266 100644 --- a/src/runtime/ustring.scm +++ b/src/runtime/ustring.scm @@ -830,21 +830,13 @@ USA. (define (burst-string string delimiter allow-runs?) ((string-splitter delimiter allow-runs?) string)) - + (define (string-replace string char1 char2) (guarantee bitless-char? char1 'string-replace) (guarantee bitless-char? char2 'string-replace) (string-map (lambda (char) (if (char=? char char1) char2 char)) string)) - -(define (reverse-string string) - (let ((builder (string-builder))) - (do ((i (fix:- (string-length string) 1) - (fix:- i 1))) - ((not (fix:>= i 0))) - (builder (string-ref string i))) - (builder))) (define (string-8-bit? string) (receive (string start end) (translate-slice string 0 (string-length string))