Closed alt-vena closed 5 years ago
Is it a good idea having virtually the same doc-string for every method? Maybe move it to a defgeneric.
And is it a good idea calling read-byte? Since these are lists and vectors, maybe you can just use the as such.
@stassats I will have a look at the doc-strings again. I see your point.
The reason I am calling read-byte and not aref etc is that there might be a transformer function or some other functionality when reading from the stream. This is also how it is implemented for normal flexi-streams.
read-sequence does not call read-byte repeatedly.
hm, you are correct. Have a look at the following though. read-byte calls the transformer on the read byte but read-sequence does not. Is this consistent at all?
(defmethod stream-read-byte ((stream list-input-stream))
"Reads one byte by simply popping it off of the top of the list."
(declare #.*standard-optimize-settings*)
(check-if-open stream)
(with-accessors ((list list-stream-list))
stream
(transform-octet stream (or (pop list) (return-from stream-read-byte :eof)))))
(defmethod stream-read-sequence ((stream list-input-stream) sequence start end &key)
"Repeatedly pops elements from the list until it's empty."
(declare #.*standard-optimize-settings*)
(declare (fixnum start end))
(with-accessors ((list list-stream-list))
stream
(loop for index of-type fixnum from start below end
while list
do (setf (elt sequence index) (pop list))
finally (return index))))
Also, this is how peek-byte is implemented for normal flexi-streams:
I made an attempt to fix up the doc-string. I defined a defgeneric in in-memory.lisp. Although this might not be the most natural place as in-memory streams are kind of ad-hoc to this library? At least I am not getting redefinition warnings like this.
edit: wrote in wrong PR..
I would love to see this merged!
peek-byte is not implemented for in-memory streams. I have added the methods.