Changeset 5406


Ignore:
Timestamp:
Oct 23, 2006, 4:40:30 AM (18 years ago)
Author:
Gary Byers
Message:

Optimize write-string on string streams a little.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-1/l1-streams.lisp

    r5398 r5406  
    41884188(defun string-output-stream-ioblock-write-simple-string (ioblock string start-char num-chars)
    41894189  (declare (simple-string string)
    4190            (fixnum start-char num-chars))
     4190           (fixnum start-char num-chars)
     4191           (optimize (speed 3) (safety 0)))
    41914192  (let* ((out (string-output-stream-ioblock-string ioblock))
    41924193         (index (string-output-stream-ioblock-index ioblock))
     
    41984199      (let* ((newlen (+ need need))
    41994200             (new (make-string newlen)))
    4200         (declare (fixnum newlen))
    4201         (%copy-ivector-to-ivector out 0 new 0 (the fixnum (ash len 2)))
     4201        (declare (fixnum newlen) (simple-string new))
     4202        (dotimes (i len)
     4203          (setf (schar new i) (schar out i)))
    42024204        (setq out new)
    42034205        (setf (string-output-stream-ioblock-string ioblock) new)))
    4204     (%copy-ivector-to-ivector string
    4205                               (the fixnum (ash start-char 2))
    4206                               out
    4207                               (the fixnum (ash index 2))
    4208                               (the fixnum (ash num-chars 2)))
    4209     (setf (string-output-stream-ioblock-index ioblock) need)
    4210     (let* ((end (+ start-char num-chars))
    4211            (nlpos (position #\newline string :start start-char :end end :from-end t)))
    4212       (declare (fixnum end))
    4213       (if nlpos
    4214         (setf (ioblock-charpos ioblock) (the fixnum (- end (the fixnum nlpos))))
    4215         (incf (ioblock-charpos ioblock) num-chars)))
    4216     num-chars))
     4206    (do* ((src start-char (1+ src))
     4207          (dest index (1+ dest))
     4208          (nlpos nil)
     4209          (end (+ start-char num-chars)))
     4210         ((= src end)
     4211          (setf (string-output-stream-ioblock-index ioblock) need)
     4212          (if nlpos
     4213            (setf (ioblock-charpos ioblock) (the fixnum (- end (the fixnum nlpos))))
     4214            (incf (ioblock-charpos ioblock) num-chars))
     4215          num-chars)
     4216      (let* ((char (schar string src)))
     4217        (if (eql char #\Newline)
     4218          (setq nlpos src))
     4219        (setf (schar out dest) char)))))
     4220
    42174221
    42184222(defmethod stream-position ((stream string-output-stream) &optional newpos)
     
    53525356
    53535357
    5354 (defresource *string-output-stream-pool*
    5355   :constructor (make-string-output-stream)
    5356   :initializer 'stream-clear-output)
     5358
    53575359
    53585360;;;File streams.
Note: See TracChangeset for help on using the changeset viewer.