-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid needless allocation in read-bytevector! #950
Conversation
This change switches the implementation strategy to basing read-bytevector on top of read-bytevector! rather than the other way around.
228edb8
to
d0e6dc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm not sure why I did it this way - it should really be done in the FFI but your approach is better until I get around to that.
lib/scheme/extras.scm
Outdated
@@ -135,36 +135,31 @@ | |||
(if (zero? n) | |||
#u8() | |||
(let ((in (if (pair? o) (car o) (current-input-port))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
lib/scheme/extras.scm
Outdated
(res (read-bytevector! vec in))) | ||
(cond ((eof-object? res) res) | ||
((< res n) (subbytes vec 0 i)) | ||
(else res))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(else res))))) | |
(else vec))))) |
lib/scheme/extras.scm
Outdated
(vec (make-bytevector n)) | ||
(res (read-bytevector! vec in))) | ||
(cond ((eof-object? res) res) | ||
((< res n) (subbytes vec 0 i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
((< res n) (subbytes vec 0 i)) | |
((< res n) (subbytes vec 0 res)) |
This change switches the implementation strategy to basing read-bytevector on top of read-bytevector! rather than the other way around. Bonus: It's a bit less code than previously and is less surprising to the reader.