Issue #339 - Fix fast path in make-string

We need to ensure the code point buffer only contains a single byte in order to use the fast path for string creation. For example if there is one code point that is 2 bytes large we need to use the slow path.
This commit is contained in:
Justin Ethier 2019-09-23 13:28:52 -04:00
parent e6c23e25c1
commit e211e3f64d
2 changed files with 6 additions and 1 deletions

View file

@ -1048,7 +1048,7 @@
((string_type *)s)->num_cp = num_cp; ((string_type *)s)->num_cp = num_cp;
((string_type *)s)->str = alloca(sizeof(char) * (len + 1)); ((string_type *)s)->str = alloca(sizeof(char) * (len + 1));
} }
if (num_cp == 1) { /* Fast path */ if (buflen == 1) { /* Fast path */
memset(((string_type *)s)->str, ch_buf[0], len); memset(((string_type *)s)->str, ch_buf[0], len);
} else { } else {
char *buf = ((string_type *)s)->str; char *buf = ((string_type *)s)->str;

View file

@ -157,6 +157,11 @@
"abcde") "abcde")
(assert:equal "string-for-each" v '(101 100 99 98 97))) (assert:equal "string-for-each" v '(101 100 99 98 97)))
;; UTF-8 / Strings
(assert:equal "UTF8 string length" (string-length (make-string 1 (integer->char 128))) 1)
(assert:equal "UTF8 bv length" (bytevector-length (string->utf8 (make-string 1 (integer->char 128)))) 2)
(assert:equal "UTF8 char" (string-ref (make-string 1 (integer->char 128)) 0) #\x80)
;; Recursion example: ;; Recursion example:
(letrec ((fnc (lambda (i) (letrec ((fnc (lambda (i)
(begin (begin