Add xstring-byte-ref and xstring-byte-set!.
authorMatt Birkholz <matt@birkholz.chandler.az.us>
Thu, 12 Sep 2013 19:07:57 +0000 (12:07 -0700)
committerMatt Birkholz <matt@birkholz.chandler.az.us>
Thu, 12 Sep 2013 19:07:57 +0000 (12:07 -0700)
Made external-string-ref and external-string-set! integrable.

src/runtime/runtime.pkg
src/runtime/string.scm

index cf4d0d24315dac1a4d001c51b1e9e566d1dc0a26..b710d8820545a55cdf5580a8498a602d591e2122 100644 (file)
@@ -1075,7 +1075,9 @@ USA.
          xstring-length
          xstring-move!
          xstring-ref
+         xstring-byte-ref
          xstring-set!
+         xstring-byte-set!
          xstring?
          xsubstring
          xsubstring-fill!
index 41567ee7e9e84089d74a2ae34a302ec96d4fbe54..f7279c8fe6897b21d29df39fb79ea8211bf99089 100644 (file)
@@ -1607,14 +1607,20 @@ USA.
        ((ucode-primitive allocate-external-string) n-bytes)
        n-bytes)))))
 
-(define (external-string-ref string index)
+(define-integrable (external-string-ref string index)
   (ascii->char
-   ((ucode-primitive read-byte-from-memory)
-    (+ (external-string-descriptor string) index))))
+   (external-string-byte-ref string index)))
 
-(define (external-string-set! string index char)
+(define-integrable (external-string-byte-ref string index)
+  ((ucode-primitive read-byte-from-memory)
+   (+ (external-string-descriptor string) index)))
+
+(define-integrable (external-string-set! string index char)
+  (external-string-byte-set! string index (char->ascii char)))
+
+(define-integrable (external-string-byte-set! string index byte)
   ((ucode-primitive write-byte-to-memory)
-   (char->ascii char)
+   byte
    (+ (external-string-descriptor string) index)))
 
 (define-integrable (external-substring-fill! string start end char)
@@ -1640,12 +1646,25 @@ USA.
        ((external-string? string) (external-string-ref string index))
        (else (error:not-xstring string 'XSTRING-REF))))
 
+(define (xstring-byte-ref string index)
+  (cond ((string? string) (vector-8b-ref string index))
+       ((wide-string? string) (wide-string-ref string index))
+       ((external-string? string) (external-string-byte-ref string index))
+       (else (error:not-xstring string 'XSTRING-BYTE-REF))))
+
 (define (xstring-set! string index char)
   (cond ((string? string) (string-set! string index char))
        ((wide-string? string) (wide-string-set! string index char))
        ((external-string? string) (external-string-set! string index char))
        (else (error:not-xstring string 'XSTRING-SET!))))
 
+(define (xstring-byte-set! string index byte)
+  (cond ((string? string) (vector-8b-set! string index byte))
+       ((wide-string? string) (wide-string-set! string index byte))
+       ((external-string? string)
+        (external-string-byte-set! string index byte))
+       (else (error:not-xstring string 'XSTRING-BYTE-SET!))))
+
 (define (xstring-move! xstring1 xstring2 start2)
   (xsubstring-move! xstring1 0 (xstring-length xstring1) xstring2 start2))