Commit 21db675c authored by Stas Boukarev's avatar Stas Boukarev
Browse files

Optimize writing of simple-base-strings on SBCL.

parent 39ace35e
......@@ -49,6 +49,9 @@
(defmethod create-test-object ((type (eql 'string)) &key object-size)
(make-string (or object-size 10000)))
(defmethod create-test-object ((type (eql 'constant-string)) &key)
#.(coerce "AAAAAAAAAAAAAAAAdddddddddddddddddddddsssssssssssss" 'simple-base-string))
(defun class-preallocation-test (storage)
(loop for class in (storage-data storage)
for length = (length (objects-of-class class))
......@@ -347,7 +347,7 @@
(write-n-bytes #.(type-code 'ascii-string) 1 stream)
(write-n-bytes (length string) +sequence-length+ stream)
(write-ascii-string string stream))
(write-ascii-string-optimized string stream))
(write-n-bytes #.(type-code 'ascii-string) 1 stream)
(write-n-bytes (length string) +sequence-length+ stream)
......@@ -257,6 +257,37 @@
(declaim (inline write-ascii-string-optimized))
(defun write-ascii-string-optimized (string stream)
(declare (optimize speed)
(simple-base-string string)
(sb-ext:muffle-conditions sb-ext:compiler-note))
(sb-sys:with-pinned-objects (string)
(let* ((length (length string))
(position (output-stream-buffer-position stream))
(string-sap (sb-sys:vector-sap string))
(new-position (sb-ext:truly-the word (+ position length))))
(declare (type word position new-position))
(cond ((<= new-position (output-stream-buffer-end stream))
(copy-mem string-sap (sb-sys:int-sap position) length)
(setf (output-stream-buffer-position stream)
((<= length +buffer-size+)
(let* ((start (output-stream-buffer-start stream))
(left (- (output-stream-buffer-end stream) position))
(left-length (sb-ext:truly-the word (- length left))))
(declare (word left left-length))
(copy-mem string-sap (sb-sys:int-sap position) left)
(flush-buffer stream)
(copy-mem (sb-sys:sap+ string-sap left)
(sb-sys:int-sap start) left-length)
(setf (output-stream-buffer-position stream)
(sb-ext:truly-the word (+ start left-length)))))
(error "Strings of more than ~a are not supported yet."
(defmacro with-io-file ((stream file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment