From 4f6ecb8c768659b166f6a779413f7045ae49f60a Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 2 Jan 2019 02:16:36 +0000 Subject: [PATCH] Integrate string operations for order of magnitude speedup. --- src/edwin/string.scm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/edwin/string.scm b/src/edwin/string.scm index 16ee86af0..3eea2d925 100644 --- a/src/edwin/string.scm +++ b/src/edwin/string.scm @@ -62,6 +62,7 @@ USA. (define byte0-index (fix:* 2 (bytes-per-object))) +(declare (integrate-operator string?)) (define (string? object) (or (object-type? (ucode-type string) object) (bytevector? object) @@ -75,12 +76,13 @@ USA. (define-integrable (%string-length string) (primitive-datum-ref string 1)) -(define (string-ref string index) +(define-integrable (string-ref string index) (integer->char (vector-8b-ref string index))) -(define (string-set! string index char) +(define-integrable (string-set! string index char) (vector-8b-set! string index (char->integer char))) +(declare (integrate-operator vector-8b-ref)) (define (vector-8b-ref string index) (if (not (string? string)) (error:not-a string? string 'vector-8b-ref)) @@ -90,6 +92,7 @@ USA. (error:bad-range-argument index 'vector-8b-ref)) (primitive-byte-ref string (fix:+ byte0-index index))) +(declare (integrate-operator vector-8b-set!)) (define (vector-8b-set! string index u8) (if (not (string? string)) (error:not-a string? string 'vector-8b-set!)) @@ -97,7 +100,7 @@ USA. (error:not-a index-fixnum? index 'vector-8b-set!)) (if (not (fix:< index (%string-length string))) (error:bad-range-argument index 'vector-8b-set!)) - (if (not (u8? u8)) + (if (not (and (index-fixnum? u8) (fix:<= u8 #xff))) (error:not-a u8? u8 'vector-8b-set!)) (primitive-byte-set! string (fix:+ byte0-index index) u8)) -- 2.25.1