Changeset 5398
- Timestamp:
- Oct 22, 2006, 7:01:15 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-streams.lisp (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-streams.lisp
r5392 r5398 408 408 (sharing nil) 409 409 (line-termination nil) 410 ( reserved1 nil)410 (unread-char-function 'ioblock-no-char-input) 411 411 (reserved2 nil) 412 412 (reserved3 nil)) … … 2616 2616 (setf (ioblock-sharing ioblock) sharing) 2617 2617 (when character-p 2618 (setf (ioblock-unread-char-function ioblock) '%ioblock-untyi) 2618 2619 (if encoding 2619 2620 (let* ((unit-size (character-encoding-code-unit-size encoding))) … … 3648 3649 (defmethod stream-read-char ((s basic-character-input-stream)) 3649 3650 (let* ((ioblock (basic-stream-ioblock s))) 3650 (declare (optimize (speed 3))) 3651 (without-interrupts 3652 (values 3653 (funcall (ioblock-read-char-function ioblock) ioblock))))) 3651 (funcall (ioblock-read-char-function ioblock) ioblock))) 3654 3652 3655 3653 … … 3657 3655 (let* ((ioblock (basic-stream-ioblock stream))) 3658 3656 (with-ioblock-input-locked (ioblock) 3659 (locally (declare (optimize (speed 3))) 3660 (without-interrupts 3661 (values 3662 (%ioblock-tyi-no-hang ioblock))))))) 3657 (values 3658 (%ioblock-tyi-no-hang ioblock))))) 3663 3659 3664 3660 (defmethod stream-peek-char ((stream basic-character-input-stream)) 3665 3661 (let* ((ioblock (basic-stream-ioblock stream))) 3666 3662 (with-ioblock-input-locked (ioblock) 3667 (locally (declare (optimize (speed 3))) 3668 (without-interrupts 3669 (values 3670 (%ioblock-peek-char ioblock))))))) 3663 (values 3664 (funcall (ioblock-peek-char-function ioblock) ioblock))))) 3671 3665 3672 3666 (defmethod stream-clear-input ((stream basic-character-input-stream)) 3673 3667 (let* ((ioblock (basic-stream-ioblock stream))) 3674 3668 (with-ioblock-input-locked (ioblock) 3675 (locally (declare (optimize (speed 3))) 3676 (without-interrupts 3677 (values 3678 (%ioblock-clear-input ioblock))))))) 3669 (values 3670 (%ioblock-clear-input ioblock))))) 3679 3671 3680 3672 (defmethod stream-unread-char ((s basic-character-input-stream) char) 3681 3673 (let* ((ioblock (basic-stream-ioblock s))) 3682 3674 (with-ioblock-input-locked (ioblock) 3683 (locally (declare (optimize (speed 3))) 3684 (without-interrupts 3685 (values 3686 (%ioblock-untyi ioblock char))))))) 3675 (values 3676 (funcall (ioblock-unread-char-function ioblock) ioblock char))))) 3687 3677 3688 3678 (defmethod stream-read-ivector ((s basic-character-input-stream) … … 3690 3680 (let* ((ioblock (basic-stream-ioblock s))) 3691 3681 (with-ioblock-input-locked (ioblock) 3692 (locally (declare (optimize (speed 3))) 3693 (without-interrupts 3694 (values 3695 (%ioblock-character-in-ivect ioblock iv start nb))))))) 3682 (values 3683 (%ioblock-character-in-ivect ioblock iv start nb))))) 3696 3684 3697 3685 (defmethod stream-read-vector ((stream basic-character-input-stream) … … 3702 3690 (let* ((ioblock (basic-stream-ioblock stream))) 3703 3691 (with-ioblock-input-locked (ioblock) 3704 (locally (declare (optimize (speed 3))) 3705 (without-interrupts 3706 (values 3707 (funcall (ioblock-character-read-vector-function ioblock) 3708 ioblock vector start end)))))))) 3692 (values 3693 (funcall (ioblock-character-read-vector-function ioblock) 3694 ioblock vector start end)))))) 3709 3695 3710 3696 (defmethod stream-read-line ((stream basic-character-input-stream)) 3711 3697 (let* ((ioblock (basic-stream-ioblock stream))) 3712 3698 (with-ioblock-input-locked (ioblock) 3713 (locally (declare (optimize (speed 3))) 3714 (without-interrupts 3715 (values 3716 (funcall (ioblock-read-line-function ioblock) ioblock))))))) 3699 (values 3700 (funcall (ioblock-read-line-function ioblock) ioblock))))) 3717 3701 3718 3702 … … 4099 4083 4100 4084 ;;; String streams. 4101 (defclass string-stream (fundamental-character-stream) 4102 ((string :initarg :string :initform nil :reader %string-stream-string))) 4103 4104 (defmethod string-stream-string ((s string-stream)) 4105 (or (%string-stream-string s) 4106 (values (stream-is-closed s)))) 4107 4108 (defmethod open-stream-p ((s string-stream)) 4109 (not (null (%string-stream-string s)))) 4110 4111 (defmethod close ((s string-stream) &key abort) 4112 (declare (ignore abort)) 4113 (when (slot-value s 'string) 4114 (setf (slot-value s 'string) nil) 4115 t)) 4085 (make-built-in-class 'string-stream 'basic-character-stream) 4116 4086 4117 4087 (defmethod print-object ((s string-stream) out) … … 4119 4089 (unless (open-stream-p s) (format out " ~s" :closed)))) 4120 4090 4121 (defclass string-output-stream (string-stream fundamental-character-output-stream) 4122 ((column :initform 0 :accessor %stream-column))) 4123 4124 (defmethod stream-write-char ((s string-output-stream) c) 4125 (if (eq c #\newline) 4126 (setf (%stream-column s) 0) 4127 (incf (%stream-column s))) 4128 (vector-push-extend c (string-stream-string s))) 4129 4130 (defmethod stream-position ((s string-output-stream) &optional newpos) 4091 (defstruct (string-stream-ioblock (:include ioblock)) 4092 string) 4093 4094 (defstruct (string-output-stream-ioblock (:include string-stream-ioblock)) 4095 (index 0)) 4096 4097 (defglobal *string-output-stream-class* (make-built-in-class 'string-output-stream 'string-stream 'basic-character-output-stream)) 4098 4099 (defglobal *fill-pointer-string-output-stream-class* (make-built-in-class 'fill-pointer-string-output-stream 'string-output-stream)) 4100 4101 (defun %%make-string-output-stream (class string write-char-function write-string-function) 4102 (let* ((stream (allocate-basic-stream class))) 4103 (initialize-basic-stream stream :element-type 'character) 4104 (let* ((ioblock (make-string-output-stream-ioblock 4105 :stream stream 4106 :device nil 4107 :string string 4108 :element-type 'character 4109 :write-char-function write-char-function 4110 :write-char-when-locked-function write-char-function 4111 :write-simple-string-function write-string-function 4112 :force-output-function #'false 4113 :close-function #'false))) 4114 (setf (basic-stream.state stream) ioblock) 4115 stream))) 4116 4117 (declaim (inline %string-push-extend)) 4118 (defun %string-push-extend (char string) 4119 (let* ((fill (%svref string target::vectorH.logsize-cell)) 4120 (size (%svref string target::vectorH.physsize-cell))) 4121 (declare (fixnum fill size)) 4122 (if (< fill size) 4123 (multiple-value-bind (data offset) (array-data-and-offset string) 4124 (declare (simple-string data) (fixnum offset)) 4125 (setf (schar data (the fixnum (+ offset fill))) char 4126 (%svref string target::vectorH.logsize-cell) (the fixnum (1+ fill)))) 4127 (vector-push-extend char string)))) 4128 4129 4130 (defun fill-pointer-string-output-stream-ioblock-write-char (ioblock char) 4131 ;; can do better (maybe much better) than VECTOR-PUSH-EXTEND here. 4132 (if (eql char #\Newline) 4133 (setf (ioblock-charpos ioblock) 0) 4134 (incf (ioblock-charpos ioblock))) 4135 (%string-push-extend char (string-stream-ioblock-string ioblock))) 4136 4137 (defmethod stream-force-output ((stream string-output-stream)) nil) 4138 4139 (defun fill-pointer-string-output-stream-ioblock-write-simple-string (ioblock string start-char num-chars) 4140 (let* ((end (+ start-char num-chars)) 4141 (nlpos (position #\Newline string :start start-char :end end :from-end t))) 4142 (if nlpos 4143 (setf (ioblock-charpos ioblock) (- end nlpos)) 4144 (incf (ioblock-charpos ioblock) num-chars)) 4145 (let* ((out (string-stream-ioblock-string ioblock))) 4146 (do* ((n 0 (1+ n)) 4147 (i start-char (1+ i))) 4148 ((= n num-chars) num-chars) 4149 (%string-push-extend (schar string i) out))))) 4150 4151 (defmethod stream-position ((s fill-pointer-string-output-stream) &optional newpos) 4131 4152 (let* ((string (string-stream-string s))) 4132 4153 (if newpos … … 4140 4161 (array-total-size (string-stream-string s)))) 4141 4162 4142 (defmethod stream-line-column ((s string-output-stream)) 4143 (%stream-column s)) 4144 4145 (defmethod stream-set-column ((s string-output-stream) new) 4146 (setf (%stream-column s) new)) 4147 4163 ;;; This creates a FILL-POINTER-STRING-OUTPUT-STREAM. 4148 4164 (defun %make-string-output-stream (string) 4149 4165 (unless (and (typep string 'string) 4150 4166 (array-has-fill-pointer-p string)) 4151 4167 (error "~S must be a string with a fill pointer.")) 4152 (make-instance 'string-output-stream :string string)) 4168 (%%make-string-output-stream *fill-pointer-string-output-stream-class* string 'fill-pointer-string-output-stream-ioblock-write-char 'fill-pointer-string-output-stream-ioblock-write-simple-string)) 4169 4170 (defun string-output-stream-ioblock-write-char (ioblock char) 4171 (let* ((string (string-output-stream-ioblock-string ioblock)) 4172 (index (string-output-stream-ioblock-index ioblock)) 4173 (len (length string))) 4174 (declare (simple-string string) 4175 (fixnum index len)) 4176 (if (eql char #\Newline) 4177 (setf (ioblock-charpos ioblock) 0) 4178 (incf (ioblock-charpos ioblock))) 4179 (if (= index len) 4180 (let* ((newlen (+ len len)) ;non-zero ! 4181 (new (make-string newlen))) 4182 (%copy-ivector-to-ivector string 0 new 0 (the fixnum (ash len 2))) 4183 (setq string new) 4184 (setf (string-output-stream-ioblock-string ioblock) new))) 4185 (setf (string-output-stream-ioblock-index ioblock) (the fixnum (1+ index)) 4186 (schar string index) char))) 4187 4188 (defun string-output-stream-ioblock-write-simple-string (ioblock string start-char num-chars) 4189 (declare (simple-string string) 4190 (fixnum start-char num-chars)) 4191 (let* ((out (string-output-stream-ioblock-string ioblock)) 4192 (index (string-output-stream-ioblock-index ioblock)) 4193 (len (length out)) 4194 (need (+ index num-chars))) 4195 (declare (simple-string out) 4196 (fixnum index len need)) 4197 (if (< len need) 4198 (let* ((newlen (+ need need)) 4199 (new (make-string newlen))) 4200 (declare (fixnum newlen)) 4201 (%copy-ivector-to-ivector out 0 new 0 (the fixnum (ash len 2))) 4202 (setq out new) 4203 (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)) 4217 4218 (defmethod stream-position ((stream string-output-stream) &optional newpos) 4219 (let* ((ioblock (basic-stream-ioblock stream))) 4220 (if (null newpos) 4221 (string-output-stream-ioblock-index ioblock) 4222 (if (and (typep newpos 'fixnum) 4223 (>= (the fixnum newpos) 0) 4224 (<= (the fixnum newpos) (length (string-output-stream-ioblock-string ioblock)))) 4225 (setf (string-output-stream-ioblock-index ioblock) newpos))))) 4226 4227 (defun make-simple-string-output-stream () 4228 (%%make-string-output-stream *string-output-stream-class* 4229 (make-string 10) 4230 'string-output-stream-ioblock-write-char 4231 'string-output-stream-ioblock-write-simple-string)) 4153 4232 4154 4233 (defun make-string-output-stream (&key (element-type 'character element-type-p)) … … 4161 4240 (error "~S argument ~S is not a subtype of ~S." 4162 4241 :element-type element-type 'character))) 4163 (make-instance 'string-output-stream 4164 :string (make-array 10 :element-type 'base-char 4165 :fill-pointer 0 4166 :adjustable t))) 4242 (make-simple-string-output-stream)) 4243 4167 4244 4168 4245 ;;;"Bounded" string output streams. 4169 (defclass truncating-string-stream (string-output-stream) 4170 ((truncated :initform nil))) 4246 (defglobal *truncating-string-output-stream-class* (make-built-in-class 'truncating-string-stream 'string-output-stream)) 4247 4248 (defun truncating-string-output-stream-ioblock-write-char (ioblock char) 4249 (let* ((stream (ioblock-stream ioblock)) 4250 (string (string-output-stream-ioblock-string ioblock)) 4251 (index (string-output-stream-ioblock-index ioblock))) 4252 (declare (fixnum index) (simple-string string)) 4253 (if (< index (the fixnum (length string))) 4254 (progn 4255 (setf (schar string index) char 4256 (string-output-stream-ioblock-index ioblock) (the fixnum (1+ index))) 4257 (if (eql char #\Newline) 4258 (setf (ioblock-charpos ioblock) 0) 4259 (incf (ioblock-charpos ioblock)))) 4260 (setf (getf (basic-stream.info stream) :truncated) t)))) 4261 4262 (defun truncating-string-output-stream-ioblock-write-simple-string (ioblock string start-char num-chars) 4263 (let* ((stream (ioblock-stream ioblock))) 4264 (do* ((n 0 (1+ n)) 4265 (i start-char (1+ i))) 4266 ((= n num-chars) num-chars) 4267 (truncating-string-output-stream-ioblock-write-char ioblock (schar string i)) 4268 (if (getf (basic-stream.info stream) :truncated) 4269 (return n))))) 4270 4271 (defun truncating-string-output-stream-truncated-p (stream) 4272 (getf (basic-stream.info stream) :truncated)) 4171 4273 4172 4274 (defun make-truncating-string-stream (len) 4173 ( make-instance 'truncating-string-stream4174 :string(make-array len4275 (%%make-string-output-stream *truncating-string-output-stream-class* 4276 (make-array len 4175 4277 :element-type 'character 4176 4278 :fill-pointer 0 4177 :adjustable nil))) 4178 4179 (defmethod stream-write-char ((s truncating-string-stream) char) 4180 (or (vector-push char (string-stream-string s)) 4181 (setf (slot-value s 'truncated) t)) 4182 char) 4183 4184 (defmethod stream-write-string ((stream truncating-string-stream) 4185 string &optional (start 0) end) 4186 (setq end (check-sequence-bounds string start end)) 4187 (locally (declare (fixnum start end)) 4188 (multiple-value-bind (vect offset) (array-data-and-offset string) 4189 (declare (fixnum offset)) 4190 (unless (zerop offset) 4191 (incf start offset) 4192 (incf end offset)) 4193 (do* ((v (string-stream-string stream)) 4194 (i start (1+ i))) 4195 ((= i end) string) 4196 (declare (fixnum i)) 4197 (if (slot-value stream 'truncated) 4198 (return string) 4199 (or (vector-push (schar vect i) v) 4200 (progn 4201 (setf (slot-value stream 'truncated) t) 4202 (return string)))))))) 4279 :adjustable nil) 4280 'truncating-string-output-stream-ioblock-write-char 4281 'truncating-string-output-stream-ioblock-write-simple-string)) 4282 4203 4283 4204 4284 ;;;One way to indent on newlines: 4205 4285 4206 (defclass indenting-string-output-stream (string-output-stream) 4207 ((prefixchar :initform nil :initarg :prefixchar) 4208 (indent :initform nil :initarg :indent :accessor indenting-string-output-stream-indent))) 4209 4210 (defun make-indenting-string-output-stream (prefixchar indent) 4211 (make-instance 'indenting-string-output-stream 4212 :string (make-array 10 4213 :element-type 'character 4214 :fill-pointer 0 4215 :adjustable t) 4216 :prefixchar prefixchar 4217 :indent indent)) 4218 4219 (defmethod stream-write-char ((s indenting-string-output-stream) c) 4220 (call-next-method) 4221 (when (eq c #\newline) 4222 (let* ((indent (slot-value s 'indent)) 4223 (prefixchar (slot-value s 'prefixchar)) 4224 (prefixlen 0)) 4286 (defglobal *indenting-string-output-stream-class* (make-built-in-class 'indenting-string-output-stream 'string-output-stream)) 4287 4288 4289 4290 (defun indenting-string-stream-ioblock-write-char (ioblock c) 4291 (string-output-stream-ioblock-write-char ioblock c) 4292 (if (eql c #\newline) 4293 (let* ((stream (ioblock-stream ioblock)) 4294 (info (basic-stream.info stream)) 4295 (indent (getf info 'indent)) 4296 (prefixlen 0) 4297 (prefixchar (getf info 'prefixchar))) 4225 4298 (when prefixchar 4226 4299 (if (typep prefixchar 'character) 4227 4300 (progn 4228 4301 (setq prefixlen 1) 4229 ( call-next-method sprefixchar))4302 (string-output-stream-ioblock-write-char ioblock prefixchar)) 4230 4303 (dotimes (i (setq prefixlen (length prefixchar))) 4231 ( call-next-method s(schar prefixchar i)))))4304 (string-output-stream-ioblock-write-char ioblock (schar prefixchar i))))) 4232 4305 (when indent 4233 4306 (dotimes (i (the fixnum (- indent prefixlen))) 4234 ( call-next-method s#\Space)))))4307 (string-output-stream-ioblock-write-char ioblock #\Space))))) 4235 4308 c) 4236 4309 4310 (defun indenting-string-stream-ioblock-write-simple-string (ioblock string start-char num-chars) 4311 (do* ((n 0 (1+ n)) 4312 (i start-char (1+ i))) 4313 ((= n num-chars) num-chars) 4314 (indenting-string-stream-ioblock-write-char ioblock (schar string i)))) 4315 4316 (defun make-indenting-string-output-stream (prefixchar indent) 4317 (let* ((stream (%%make-string-output-stream 4318 *indenting-string-output-stream-class* 4319 (make-string 10) 4320 'indenting-string-stream-ioblock-write-char 4321 'indenting-string-stream-ioblock-write-simple-string))) 4322 (setf (getf (basic-stream.info stream) 'indent) indent 4323 (getf (basic-stream.info stream) 'prefixchar) prefixchar) 4324 stream)) 4325 4326 (defun (setf indenting-string-output-stream-indent) (new stream) 4327 (if (and (typep stream 'basic-stream) 4328 (eq (basic-stream.class stream) *indenting-string-output-stream-class*)) 4329 (setf (getf (basic-stream.info stream) 'indent) new) 4330 (report-bad-arg stream 'indenting-string-output-stream))) 4331 4332 4237 4333 (defun get-output-stream-string (s) 4238 (unless (typep s 'string-output-stream) 4239 (report-bad-arg s 'string-output-stream)) 4240 (let* ((string (string-stream-string s))) 4241 (prog1 (ensure-simple-string string) 4242 (setf (fill-pointer string) 0)))) 4334 (let* ((class (if (typep s 'basic-stream) (basic-stream.class s)))) 4335 (or (eq class *string-output-stream-class*) 4336 (eq class *truncating-string-output-stream-class*) 4337 (eq class *indenting-string-output-stream-class*) 4338 (eq class *fill-pointer-string-output-stream-class*) 4339 (report-bad-arg s 'string-output-stream)) 4340 (let* ((ioblock (basic-stream-ioblock s)) 4341 (string (string-stream-ioblock-string ioblock))) 4342 (if (eq class *fill-pointer-string-output-stream-class*) 4343 (prog1 (ensure-simple-string string) 4344 (setf (fill-pointer string) 0)) 4345 (let* ((index (string-output-stream-ioblock-index ioblock)) 4346 (result (make-string index))) 4347 (declare (fixnum index)) 4348 (%copy-ivector-to-ivector string 0 result 0 (the fixnum (ash index 2))) 4349 (setf (string-output-stream-ioblock-index ioblock) 0) 4350 result))))) 4243 4351 4244 4352 ;;; String input streams. 4245 (defclass string-input-stream (string-stream fundamental-character-input-stream) 4246 ((start :initform 0 :initarg :start :accessor string-input-stream-start) 4247 (index :initarg :index :accessor string-input-stream-index) 4248 (end :initarg :end :accessor string-input-stream-end))) 4249 4250 (defmethod stream-read-char ((s string-input-stream)) 4251 (let* ((string (string-stream-string s)) 4252 (idx (string-input-stream-index s)) 4253 (end (string-input-stream-end s))) 4254 (declare (fixnum idx end)) 4353 (defglobal *string-input-stream-class* (make-built-in-class 'string-input-stream 'string-stream 'basic-character-input-stream)) 4354 4355 (defstruct (string-input-stream-ioblock (:include string-stream-ioblock)) 4356 (start 0) 4357 index 4358 end 4359 (offset 0)) 4360 4361 4362 4363 (defun string-input-stream-index (s) 4364 (if (and (typep s 'basic-stream) 4365 (eq *string-input-stream-class* (basic-stream.class s))) 4366 (let* ((ioblock (basic-stream-ioblock s))) 4367 (- (string-input-stream-ioblock-index ioblock) 4368 (string-input-stream-ioblock-offset ioblock))) 4369 (report-bad-arg s 'string-input-stream))) 4370 4371 4372 4373 (defun string-input-stream-ioblock-read-char (ioblock) 4374 (let* ((string (string-stream-ioblock-string ioblock)) 4375 (idx (string-input-stream-ioblock-index ioblock)) 4376 (end (string-input-stream-ioblock-end ioblock))) 4377 (declare (fixnum idx end) 4378 (simple-string string)) 4255 4379 (if (< idx end) 4256 (prog1 (char string idx) (setf (string-input-stream-index s) (1+ idx))) 4380 (progn (setf (string-input-stream-ioblock-index ioblock) 4381 (the fixnum (1+ idx))) 4382 (schar string idx)) 4257 4383 :eof))) 4258 4384 4259 (defmethod stream-peek-char ((s string-input-stream)) 4260 (let* ((string (string-stream-string s)) 4261 (idx (string-input-stream-index s)) 4262 (end (string-input-stream-end s))) 4263 (declare (fixnum idx end)) 4385 (defun string-input-stream-ioblock-read-line (ioblock) 4386 (let* ((string (string-stream-ioblock-string ioblock)) 4387 (idx (string-input-stream-ioblock-index ioblock)) 4388 (end (string-input-stream-ioblock-end ioblock))) 4389 (declare (fixnum idx end) 4390 (simple-string string)) 4391 (if (>= idx end) 4392 (values "" t) 4393 (let* ((pos (position #\Newline string :start idx :end end))) 4394 (if pos 4395 (locally (declare (type index pos)) 4396 (let* ((new (make-string (the fixnum (- pos idx))))) 4397 (declare (simple-base-string new)) 4398 (setf (string-input-stream-ioblock-index ioblock) 4399 (the fixnum (1+ pos))) 4400 (do* ((src idx (1+ src)) 4401 (dest 0 (1+ dest))) 4402 ((= src pos) (values new nil)) 4403 (declare (fixnum src dest)) 4404 (setf (schar new dest) (schar string src))))) 4405 (let* ((new (make-string (the fixnum (- end idx))))) 4406 (declare (simple-base-string new)) 4407 (setf (string-input-stream-ioblock-index ioblock) end) 4408 (do* ((src idx (1+ src)) 4409 (dest 0 (1+ dest))) 4410 ((= src end) (values new t)) 4411 (declare (fixnum src dest)) 4412 (setf (schar new dest) (schar string src))))))))) 4413 4414 4415 (defun string-input-stream-ioblock-peek-char (ioblock) 4416 (let* ((string (string-stream-ioblock-string ioblock)) 4417 (idx (string-input-stream-ioblock-index ioblock)) 4418 (end (string-input-stream-ioblock-end ioblock))) 4419 (declare (fixnum idx end) 4420 (simple-string string)) 4264 4421 (if (< idx end) 4265 ( char string idx)4422 (schar string idx) 4266 4423 :eof))) 4267 4424 4268 (defmethod stream-unread-char ((s string-input-stream) c) 4269 (let* ((data (string-stream-string s)) 4270 (idx (string-input-stream-index s)) 4271 (start (string-input-stream-start s))) 4272 (declare (fixnum idx start)) 4425 (defun string-input-stream-ioblock-unread-char (ioblock char) 4426 (let* ((string (string-stream-ioblock-string ioblock)) 4427 (idx (string-input-stream-ioblock-index ioblock)) 4428 (start (string-input-stream-ioblock-start ioblock))) 4429 (declare (fixnum idx start) 4430 (simple-string string)) 4273 4431 (unless (> idx start) 4274 (error "Nothing has been read from ~s yet." s))4432 (error "Nothing has been read from ~s yet." (ioblock-stream ioblock))) 4275 4433 (decf idx) 4276 (unless (eq c (char data idx)) 4277 (error "~a was not the last character read from ~s" c s)) 4278 (setf (string-input-stream-index s) idx) 4279 c)) 4280 4281 4282 4434 (unless (eq char (schar string idx)) 4435 (error "~a was not the last character read from ~s" char (ioblock-stream ioblock))) 4436 (setf (string-input-stream-ioblock-index ioblock) idx) 4437 char)) 4438 4439 4283 4440 (defmethod stream-eofp ((s string-input-stream)) 4284 (let* ((idx (string-input-stream-index s)) 4285 (end (string-input-stream-end s))) 4441 (let* ((ioblock (basic-stream-ioblock s)) 4442 (idx (string-input-stream-ioblock-index ioblock)) 4443 (end (string-input-stream-ioblock-end ioblock))) 4286 4444 (declare (fixnum idx end)) 4287 4445 (>= idx end))) 4288 4446 4289 4447 (defmethod stream-listen ((s string-input-stream)) 4290 (let* ((idx (string-input-stream-index s)) 4291 (end (string-input-stream-end s))) 4448 (let* ((ioblock (basic-stream-ioblock s)) 4449 (idx (string-input-stream-ioblock-index ioblock)) 4450 (end (string-input-stream-ioblock-end ioblock))) 4292 4451 (declare (fixnum idx end)) 4293 4452 (< idx end))) 4294 4453 4295 4296 4297 (defmethod stream-position ((s string-input-stream) &optional newpos)4298 (let* ((start (string-input-stream-start s))4299 (end (string-input-stream-end s))4300 (len (- end start)))4301 (declare (fixnum start end len))4302 (if newpos4303 (if (and (>= newpos 0) (<= newpos len))4304 (setf (string-input-stream-index s) (+ start newpos)))4305 (- (string-input-stream-index s) start))))4306 4307 (defmethod stream-length ((s string-input-stream) &optional newlen)4308 (unless newlen4309 (- (string-input-stream-end s) (string-input-stream-start s))))4310 4454 4311 4455 (defun make-string-input-stream (string &optional (start 0) … … 4314 4458 START and END in order." 4315 4459 (setq end (check-sequence-bounds string start end)) 4316 (make-instance 'string-input-stream 4317 :string string 4318 :start start 4319 :index start 4320 :end end)) 4460 (multiple-value-bind (data offset) (array-data-and-offset string) 4461 (unless (typep data 'simple-base-string) 4462 (report-bad-arg string 'string)) 4463 (incf start offset) 4464 (incf end offset) 4465 (let* ((stream (make-basic-stream-instance 4466 *string-input-stream-class* 4467 :element-type 'character)) 4468 (ioblock (make-string-input-stream-ioblock 4469 :stream stream 4470 :device nil 4471 :string data 4472 :start start 4473 :index start 4474 :end end 4475 :read-char-function 'string-input-stream-ioblock-read-char 4476 :read-char-when-locked-function 'string-input-stream-ioblock-read-char 4477 :peek-char-function 'string-input-stream-ioblock-peek-char 4478 :character-read-vector-function 'generic-character-read-vector 4479 :close-function #'false 4480 :unread-char-function 'string-input-stream-ioblock-unread-char 4481 :read-line-function 'string-input-stream-ioblock-read-line 4482 ))) 4483 (setf (basic-stream.state stream) ioblock) 4484 stream))) 4485 4486 (defun string-stream-string (s) 4487 (let* ((class (if (typep s 'basic-stream) (basic-stream.class s)))) 4488 (or (eq class *string-output-stream-class*) 4489 (eq class *truncating-string-output-stream-class*) 4490 (eq class *indenting-string-output-stream-class*) 4491 (report-bad-arg s 'string-output-stream))) 4492 (string-stream-ioblock-string (basic-stream-ioblock s))) 4493 4321 4494 4322 4495 … … 4414 4587 (let* ((ioblock (stream-ioblock stream nil))) 4415 4588 (when ioblock 4416 (locally (declare (optimize (speed 3))) 4417 (without-interrupts 4418 (values 4419 (%ioblock-close ioblock))))))) 4589 (%ioblock-close ioblock)))) 4420 4590 4421 4591 (defmethod close :before ((stream buffered-output-stream-mixin) &key abort) … … 4433 4603 (let* ((ioblock (basic-stream.state stream))) 4434 4604 (when ioblock 4435 (locally (declare (optimize (speed 3))) 4436 (without-interrupts 4437 (values 4438 (%ioblock-close ioblock))))))) 4605 (%ioblock-close ioblock)))) 4439 4606 4440 4607 … … 4491 4658 (defmethod stream-read-char ((stream buffered-character-input-stream-mixin)) 4492 4659 (let* ((ioblock (stream-ioblock stream t))) 4493 (locally (declare (optimize (speed 3))) 4494 (without-interrupts 4495 (values 4496 (funcall (ioblock-read-char-function ioblock) ioblock)))))) 4660 (funcall (ioblock-read-char-function ioblock) ioblock))) 4497 4661 4498 4662 (defmethod stream-read-char-no-hang ((stream buffered-character-input-stream-mixin)) 4499 4663 (with-stream-ioblock-input (ioblock stream :speedy t) 4500 (locally (declare (optimize (speed 3))) 4501 (without-interrupts 4502 (values 4503 (%ioblock-tyi-no-hang ioblock)))))) 4664 (%ioblock-tyi-no-hang ioblock))) 4504 4665 4505 4666 (defmethod stream-peek-char ((stream buffered-character-input-stream-mixin)) 4506 4667 (with-stream-ioblock-input (ioblock stream :speedy t) 4507 (locally (declare (optimize (speed 3))) 4508 (without-interrupts 4509 (values 4510 (%ioblock-peek-char ioblock)))))) 4668 (values 4669 (%ioblock-peek-char ioblock)))) 4511 4670 4512 4671 (defmethod stream-clear-input ((stream buffered-input-stream-mixin)) 4513 4672 (with-stream-ioblock-input (ioblock stream :speedy t) 4514 (locally (declare (optimize (speed 3))) 4515 (without-interrupts 4516 (values 4517 (%ioblock-clear-input ioblock)))))) 4673 (values 4674 (%ioblock-clear-input ioblock)))) 4518 4675 4519 4676 (defmethod stream-unread-char ((stream buffered-character-input-stream-mixin) char) 4520 4677 (with-stream-ioblock-input (ioblock stream :speedy t) 4521 ( %ioblock-untyiioblock char))4678 (funcall (ioblock-unread-char-function ioblock) ioblock char)) 4522 4679 char) 4523 4680 4524 4681 (defmethod stream-read-byte ((stream buffered-binary-input-stream-mixin)) 4525 4682 (let* ((ioblock (stream-ioblock stream t))) 4526 (locally (declare (optimize (speed 3))) 4527 (without-interrupts 4528 (values 4529 (funcall (ioblock-read-byte-function ioblock) ioblock)))))) 4683 (funcall (ioblock-read-byte-function ioblock) ioblock))) 4530 4684 4531 4685 (defmethod stream-read-byte ((stream basic-binary-input-stream)) 4532 4686 (let* ((ioblock (basic-stream-ioblock stream))) 4533 (locally (declare (optimize (speed 3))) 4534 (without-interrupts 4535 (values 4536 (funcall (ioblock-read-byte-function ioblock) ioblock)))))) 4687 (funcall (ioblock-read-byte-function ioblock) ioblock))) 4537 4688 4538 4689 (defmethod stream-eofp ((stream buffered-input-stream-mixin)) 4539 4690 (with-stream-ioblock-input (ioblock stream :speedy t) 4540 (locally (declare (optimize (speed 3))) 4541 (without-interrupts 4542 (values 4543 (%ioblock-eofp ioblock)))))) 4691 (values 4692 (%ioblock-eofp ioblock)))) 4544 4693 4545 4694 (defmethod stream-eofp ((stream basic-input-stream)) … … 4550 4699 (defmethod stream-listen ((stream buffered-input-stream-mixin)) 4551 4700 (with-stream-ioblock-input (ioblock stream :speedy t) 4552 (locally (declare (optimize (speed 3))) 4553 (without-interrupts 4554 (values 4555 (%ioblock-listen ioblock)))))) 4701 (values 4702 (%ioblock-listen ioblock)))) 4556 4703 4557 4704 (defmethod stream-listen ((stream basic-input-stream)) 4558 4705 (let* ((ioblock (basic-stream-ioblock stream))) 4559 4706 (with-ioblock-input-locked (ioblock) 4560 (locally (declare (optimize (speed 3))) 4561 (without-interrupts 4562 (values 4563 (%ioblock-listen ioblock))))))) 4707 (values 4708 (%ioblock-listen ioblock))))) 4564 4709 4565 4710 … … 4567 4712 byte) 4568 4713 (let* ((ioblock (stream-ioblock stream t))) 4569 (locally (declare (optimize (speed 3))) 4570 (without-interrupts 4571 (values 4572 (funcall (ioblock-write-byte-function ioblock) ioblock byte)))))) 4714 (funcall (ioblock-write-byte-function ioblock) ioblock byte))) 4573 4715 4574 4716 (defmethod stream-write-byte ((stream basic-binary-output-stream) byte) 4575 4717 (let* ((ioblock (basic-stream-ioblock stream))) 4576 (locally (declare (optimize (speed 3))) 4577 (without-interrupts 4578 (values 4579 (funcall (ioblock-write-byte-function ioblock) ioblock byte)))))) 4718 (funcall (ioblock-write-byte-function ioblock) ioblock byte))) 4580 4719 4581 4720 (defmethod stream-write-char ((stream buffered-character-output-stream-mixin) char) 4582 4721 (let* ((ioblock (stream-ioblock stream t))) 4583 (locally (declare (optimize (speed 3))) 4584 (without-interrupts 4585 (values 4586 (funcall (ioblock-write-char-function ioblock) ioblock char)))))) 4722 (funcall (ioblock-write-char-function ioblock) ioblock char))) 4587 4723 4588 4724 (defmethod stream-write-char ((stream basic-character-output-stream) char) 4589 4725 (let* ((ioblock (basic-stream-ioblock stream))) 4590 (locally (declare (optimize (speed 3))) 4591 (without-interrupts 4592 (values 4593 (funcall (ioblock-write-char-function ioblock) ioblock char)))))) 4726 (funcall (ioblock-write-char-function ioblock) ioblock char))) 4594 4727 4595 4728 4596 4729 (defmethod stream-clear-output ((stream buffered-output-stream-mixin)) 4597 4730 (with-stream-ioblock-output (ioblock stream :speedy t) 4598 (locally (declare (optimize (speed 3))) 4599 (without-interrupts 4600 (values 4601 (%ioblock-clear-output ioblock))))) 4731 (%ioblock-clear-output ioblock)) 4602 4732 nil) 4603 4733 … … 4605 4735 (let* ((ioblock (basic-stream-ioblock stream))) 4606 4736 (with-ioblock-output-locked (ioblock) 4607 (locally (declare (optimize (speed 3))) 4608 (without-interrupts 4609 (values 4610 (%ioblock-clear-output ioblock))))) 4737 (%ioblock-clear-output ioblock)) 4611 4738 nil)) 4612 4739 … … 4633 4760 (defmethod stream-force-output ((stream buffered-output-stream-mixin)) 4634 4761 (with-stream-ioblock-output (ioblock stream :speedy t) 4635 (locally (declare (optimize (speed 3))) 4636 (without-interrupts 4637 (values 4638 (%ioblock-force-output ioblock nil)))) 4762 (%ioblock-force-output ioblock nil) 4639 4763 nil)) 4640 4764 … … 4642 4766 (let* ((ioblock (basic-stream-ioblock stream))) 4643 4767 (with-ioblock-output-locked (ioblock) 4644 (locally (declare (optimize (speed 3))) 4645 (without-interrupts 4646 (values 4647 (%ioblock-force-output ioblock nil)))) 4768 (%ioblock-force-output ioblock nil) 4648 4769 nil))) 4649 4770 4650 4771 (defmethod maybe-stream-force-output ((stream buffered-output-stream-mixin)) 4651 4772 (with-stream-ioblock-output-maybe (ioblock stream :speedy t) 4652 (locally (declare (optimize (speed 3))) 4653 (without-interrupts 4654 (values 4655 (%ioblock-force-output ioblock nil)))) 4773 (%ioblock-force-output ioblock nil) 4656 4774 nil)) 4657 4775 … … 4659 4777 (let* ((ioblock (basic-stream-ioblock stream))) 4660 4778 (with-ioblock-output-locked-maybe (ioblock) 4661 (locally (declare (optimize (speed 3))) 4662 (without-interrupts 4663 (values 4664 (%ioblock-force-output ioblock nil)))) 4779 (%ioblock-force-output ioblock nil) 4665 4780 nil))) 4666 4781 4667 4782 (defmethod stream-finish-output ((stream buffered-output-stream-mixin)) 4668 4783 (with-stream-ioblock-output (ioblock stream :speedy t) 4669 (locally (declare (optimize (speed 3))) 4670 (without-interrupts 4671 (values 4672 (%ioblock-force-output ioblock t)))) 4784 (%ioblock-force-output ioblock t) 4673 4785 nil)) 4674 4786 … … 4676 4788 (let* ((ioblock (basic-stream-ioblock stream))) 4677 4789 (with-ioblock-output-locked (ioblock) 4678 (locally (declare (optimize (speed 3))) 4679 (without-interrupts 4680 (values 4681 (%ioblock-force-output ioblock t)))) 4790 (%ioblock-force-output ioblock t) 4682 4791 nil))) 4683 4792 … … 4690 4799 (if (and (typep string 'simple-string) 4691 4800 (not start-p)) 4692 (locally (declare (optimize (speed 3))) 4693 (without-interrupts 4694 (values 4695 (funcall (ioblock-write-simple-string-function ioblock) 4696 ioblock string 0 (length string))))) 4801 (funcall (ioblock-write-simple-string-function ioblock) 4802 ioblock string 0 (length string)) 4697 4803 (progn 4698 4804 (setq end (check-sequence-bounds string start end)) … … 4705 4811 (incf start offset) 4706 4812 (incf end offset)) 4707 (locally (declare (optimize (speed 3))) 4708 (without-interrupts 4709 (values 4710 (funcall (ioblock-write-simple-string-function ioblock) 4711 ioblock arr start (the fixnum (- end start))))))))))) 4813 (funcall (ioblock-write-simple-string-function ioblock) 4814 ioblock arr start (the fixnum (- end start)))))))) 4712 4815 string) 4713 4816 … … 4719 4822 (if (and (typep string 'simple-string) 4720 4823 (not start-p)) 4721 (locally (declare (optimize (speed 3))) 4722 (without-interrupts 4723 (values 4724 (funcall (ioblock-write-simple-string-function ioblock) 4725 ioblock string 0 (length string))))) 4824 (values 4825 (funcall (ioblock-write-simple-string-function ioblock) 4826 ioblock string 0 (length string))) 4726 4827 (progn 4727 4828 (setq end (check-sequence-bounds string start end)) … … 4734 4835 (incf start offset) 4735 4836 (incf end offset)) 4736 (locally (declare (optimize (speed 3))) 4737 (without-interrupts 4738 (values 4837 (values 4739 4838 (funcall (ioblock-write-simple-string-function ioblock) 4740 ioblock arr start (the fixnum (- end start)))))))))) ))4839 ioblock arr start (the fixnum (- end start)))))))))) 4741 4840 string) 4742 4841 … … 4745 4844 iv start length) 4746 4845 (with-stream-ioblock-output (ioblock s :speedy t) 4747 (locally (declare (optimize (speed 3))) 4748 (without-interrupts 4749 (values 4750 (%ioblock-out-ivect ioblock iv start length)))))) 4846 (values 4847 (%ioblock-out-ivect ioblock iv start length)))) 4751 4848 4752 4849 (defmethod stream-write-ivector ((s basic-output-stream) … … 4754 4851 (let* ((ioblock (basic-stream-ioblock s))) 4755 4852 (with-ioblock-output-locked (ioblock) 4756 (locally (declare (optimize (speed 3))) 4757 (without-interrupts 4758 (values 4759 (%ioblock-out-ivect ioblock iv start length))))))) 4853 (values 4854 (%ioblock-out-ivect ioblock iv start length))))) 4760 4855 4761 4856 … … 4763 4858 iv start nb) 4764 4859 (with-stream-ioblock-input (ioblock s :speedy t) 4765 (locally (declare (optimize (speed 3))) 4766 (without-interrupts 4767 (values 4768 (%ioblock-character-in-ivect ioblock iv start nb)))))) 4860 (values 4861 (%ioblock-character-in-ivect ioblock iv start nb)))) 4769 4862 4770 4863 (defmethod stream-read-ivector ((s buffered-binary-input-stream-mixin) 4771 4864 iv start nb) 4772 4865 (with-stream-ioblock-input (ioblock s :speedy t) 4773 (locally (declare (optimize (speed 3))) 4774 (without-interrupts 4775 (values 4776 (%ioblock-binary-in-ivect ioblock iv start nb)))))) 4866 (values 4867 (%ioblock-binary-in-ivect ioblock iv start nb)))) 4777 4868 4778 4869 … … 4785 4876 (let* ((total (- end start))) 4786 4877 (declare (fixnum total)) 4787 (locally (declare (optimize (speed 3))) 4788 (without-interrupts 4789 (values 4878 (values 4790 4879 (funcall (ioblock-write-simple-string-function ioblock) 4791 ioblock vector start total)))))) ))4880 ioblock vector start total)))))) 4792 4881 4793 4882 (defmethod stream-write-vector ((stream basic-character-output-stream) … … 4800 4889 (declare (fixnum total)) 4801 4890 (with-ioblock-output-locked (ioblock) 4802 (locally (declare (optimize (speed 3))) 4803 (without-interrupts 4804 (values 4891 (values 4805 4892 (funcall (ioblock-write-simple-string-function ioblock) 4806 ioblock vector start total)))))) ))4893 ioblock vector start total)))))) 4807 4894 4808 4895 (defmethod stream-write-vector ((stream buffered-binary-output-stream-mixin) … … 4810 4897 (declare (fixnum start end)) 4811 4898 (with-stream-ioblock-output (ioblock stream :speedy t) 4812 (without-interrupts 4813 (let* ((out (ioblock-outbuf ioblock)) 4814 (buf (io-buffer-buffer out)) 4815 (written 0) 4816 (limit (io-buffer-limit out)) 4817 (total (- end start)) 4818 (buftype (typecode buf))) 4819 (declare (fixnum buftype written total limit)) 4820 (if (not (= (the fixnum (typecode vector)) buftype)) 4821 (do* ((i start (1+ i)) 4822 (wbf (ioblock-write-byte-function ioblock))) 4823 ((= i end)) 4824 (let ((byte (uvref vector i))) 4825 (funcall wbf ioblock byte))) 4826 (do* ((pos start (+ pos written)) 4827 (left total (- left written))) 4828 ((= left 0)) 4829 (declare (fixnum pos left)) 4830 (setf (ioblock-dirty ioblock) t) 4831 (let* ((index (io-buffer-idx out)) 4832 (count (io-buffer-count out)) 4833 (avail (- limit index))) 4834 (declare (fixnum index avail count)) 4835 (cond 4836 ((= (setq written avail) 0) 4837 (%ioblock-force-output ioblock nil)) 4838 (t 4839 (if (> written left) 4840 (setq written left)) 4841 (%copy-ivector-to-ivector 4842 vector 4843 (ioblock-elements-to-octets ioblock pos) 4844 buf 4845 (ioblock-elements-to-octets ioblock index) 4846 (ioblock-elements-to-octets ioblock written)) 4847 (setf (ioblock-dirty ioblock) t) 4848 (incf index written) 4849 (if (> index count) 4850 (setf (io-buffer-count out) index)) 4851 (setf (io-buffer-idx out) index) 4852 (if (= index limit) 4853 (%ioblock-force-output ioblock nil))))))))))) 4899 (let* ((out (ioblock-outbuf ioblock)) 4900 (buf (io-buffer-buffer out)) 4901 (written 0) 4902 (limit (io-buffer-limit out)) 4903 (total (- end start)) 4904 (buftype (typecode buf))) 4905 (declare (fixnum buftype written total limit)) 4906 (if (not (= (the fixnum (typecode vector)) buftype)) 4907 (do* ((i start (1+ i)) 4908 (wbf (ioblock-write-byte-function ioblock))) 4909 ((= i end)) 4910 (let ((byte (uvref vector i))) 4911 (funcall wbf ioblock byte))) 4912 (do* ((pos start (+ pos written)) 4913 (left total (- left written))) 4914 ((= left 0)) 4915 (declare (fixnum pos left)) 4916 (setf (ioblock-dirty ioblock) t) 4917 (let* ((index (io-buffer-idx out)) 4918 (count (io-buffer-count out)) 4919 (avail (- limit index))) 4920 (declare (fixnum index avail count)) 4921 (cond 4922 ((= (setq written avail) 0) 4923 (%ioblock-force-output ioblock nil)) 4924 (t 4925 (if (> written left) 4926 (setq written left)) 4927 (%copy-ivector-to-ivector 4928 vector 4929 (ioblock-elements-to-octets ioblock pos) 4930 buf 4931 (ioblock-elements-to-octets ioblock index) 4932 (ioblock-elements-to-octets ioblock written)) 4933 (setf (ioblock-dirty ioblock) t) 4934 (incf index written) 4935 (if (> index count) 4936 (setf (io-buffer-count out) index)) 4937 (setf (io-buffer-idx out) index) 4938 (if (= index limit) 4939 (%ioblock-force-output ioblock nil)))))))))) 4854 4940 4855 4941 (defmethod stream-write-vector ((stream basic-binary-output-stream) … … 4858 4944 (let* ((ioblock (basic-stream-ioblock stream))) 4859 4945 (with-ioblock-output-locked (ioblock) 4860 (without-interrupts 4861 (let* ((out (ioblock-outbuf ioblock)) 4862 (buf (io-buffer-buffer out)) 4863 (written 0) 4864 (limit (io-buffer-limit out)) 4865 (total (- end start)) 4866 (buftype (typecode buf))) 4867 (declare (fixnum buftype written total limit)) 4868 (if (not (= (the fixnum (typecode vector)) buftype)) 4869 (do* ((i start (1+ i)) 4870 (wbf (ioblock-write-byte-function ioblock))) 4871 ((= i end)) 4872 (let ((byte (uvref vector i))) 4873 (when (characterp byte) 4874 (setq byte (char-code byte))) 4875 (funcall wbf ioblock byte))) 4876 (do* ((pos start (+ pos written)) 4877 (left total (- left written))) 4878 ((= left 0)) 4879 (declare (fixnum pos left)) 4880 (setf (ioblock-dirty ioblock) t) 4881 (let* ((index (io-buffer-idx out)) 4882 (count (io-buffer-count out)) 4883 (avail (- limit index))) 4884 (declare (fixnum index avail count)) 4885 (cond 4886 ((= (setq written avail) 0) 4887 (%ioblock-force-output ioblock nil)) 4888 (t 4889 (if (> written left) 4890 (setq written left)) 4891 (%copy-ivector-to-ivector 4892 vector 4893 (ioblock-elements-to-octets ioblock pos) 4894 buf 4895 (ioblock-elements-to-octets ioblock index) 4896 (ioblock-elements-to-octets ioblock written)) 4897 (setf (ioblock-dirty ioblock) t) 4898 (incf index written) 4899 (if (> index count) 4900 (setf (io-buffer-count out) index)) 4901 (setf (io-buffer-idx out) index) 4902 (if (= index limit) 4903 (%ioblock-force-output ioblock nil)))))))))))) 4946 (let* ((out (ioblock-outbuf ioblock)) 4947 (buf (io-buffer-buffer out)) 4948 (written 0) 4949 (limit (io-buffer-limit out)) 4950 (total (- end start)) 4951 (buftype (typecode buf))) 4952 (declare (fixnum buftype written total limit)) 4953 (if (not (= (the fixnum (typecode vector)) buftype)) 4954 (do* ((i start (1+ i)) 4955 (wbf (ioblock-write-byte-function ioblock))) 4956 ((= i end)) 4957 (let ((byte (uvref vector i))) 4958 (when (characterp byte) 4959 (setq byte (char-code byte))) 4960 (funcall wbf ioblock byte))) 4961 (do* ((pos start (+ pos written)) 4962 (left total (- left written))) 4963 ((= left 0)) 4964 (declare (fixnum pos left)) 4965 (setf (ioblock-dirty ioblock) t) 4966 (let* ((index (io-buffer-idx out)) 4967 (count (io-buffer-count out)) 4968 (avail (- limit index))) 4969 (declare (fixnum index avail count)) 4970 (cond 4971 ((= (setq written avail) 0) 4972 (%ioblock-force-output ioblock nil)) 4973 (t 4974 (if (> written left) 4975 (setq written left)) 4976 (%copy-ivector-to-ivector 4977 vector 4978 (ioblock-elements-to-octets ioblock pos) 4979 buf 4980 (ioblock-elements-to-octets ioblock index) 4981 (ioblock-elements-to-octets ioblock written)) 4982 (setf (ioblock-dirty ioblock) t) 4983 (incf index written) 4984 (if (> index count) 4985 (setf (io-buffer-count out) index)) 4986 (setf (io-buffer-idx out) index) 4987 (if (= index limit) 4988 (%ioblock-force-output ioblock nil))))))))))) 4904 4989 4905 4990 … … 4912 4997 (let* ((ioblock (basic-stream-ioblock stream))) 4913 4998 (with-ioblock-input-locked (ioblock) 4914 (locally (declare (optimize (speed 3))) 4915 (without-interrupts 4916 (values 4917 (%ioblock-binary-read-vector ioblock vector start end)))))))) 4999 (values 5000 (%ioblock-binary-read-vector ioblock vector start end)))))) 4918 5001 4919 5002 (defmethod stream-read-vector ((stream buffered-character-input-stream-mixin) … … 4923 5006 (call-next-method) 4924 5007 (with-stream-ioblock-input (ioblock stream :speedy t) 4925 (locally (declare (optimize (speed 3))) 4926 (without-interrupts 4927 (values 4928 (funcall (ioblock-character-read-vector-function ioblock) 4929 ioblock vector start end))))))) 5008 (values 5009 (funcall (ioblock-character-read-vector-function ioblock) 5010 ioblock vector start end))))) 4930 5011 4931 5012 … … 4937 5018 (call-next-method) 4938 5019 (with-stream-ioblock-input (ioblock stream :speedy t) 4939 (locally (declare (optimize (speed 3))) 4940 (without-interrupts 4941 (values 4942 (%ioblock-binary-read-vector ioblock vector start end))))))) 5020 (values 5021 (%ioblock-binary-read-vector ioblock vector start end))))) 4943 5022 4944 5023
Note:
See TracChangeset
for help on using the changeset viewer.
