From e2bcc52ce55662782381b387512cb9b3e4c1da5d Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Fri, 27 Jan 2017 12:58:39 -0800 Subject: [PATCH] Don't return legacy strings containing UTF-8. --- src/runtime/symbol.scm | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/runtime/symbol.scm b/src/runtime/symbol.scm index 2ab047c63..735952c47 100644 --- a/src/runtime/symbol.scm +++ b/src/runtime/symbol.scm @@ -81,25 +81,30 @@ USA. (legacy-string-downcase string) (ustring-downcase string))) +(define (symbol-name symbol) + (if (not (symbol? symbol)) + (error:not-a symbol? symbol 'symbol-name)) + (let* ((bytes (system-pair-car symbol)) + (string (object-new-type (ucode-type string) bytes))) + (if (ascii-string? string) + ;; Needed during cold load. + string + (utf8->string bytes)))) + (define (ascii-string? string) - (and (legacy-string? string) - (let ((end (legacy-string-length string))) + (and ((ucode-primitive string?) string) + (let ((end ((ucode-primitive string-length) string))) (let loop ((i 0)) (if (fix:< i end) - (and (fix:< (vector-8b-ref string i) #x80) + (and (fix:< ((ucode-primitive vector-8b-ref) string i) #x80) (loop (fix:+ i 1))) #t))))) -(define (symbol-name symbol) - (if (not (symbol? symbol)) - (error:not-a symbol? symbol 'symbol-name)) - (object-new-type (ucode-type string) (system-pair-car symbol))) - (define (symbol-hash symbol #!optional modulus) - (legacy-string-hash (symbol-name symbol) modulus)) + (ustring-hash (symbol-name symbol) modulus)) (define (symbol? x y) - (legacy-string