Skip to content

Conversation

@BlobCodes
Copy link
Contributor

Closes #14605

Adds the proposed #read_greedy method which tries to fill a Slice multiple times if it was only filled partially by the read method.

Since some users seem to expect this kind of behaviour from #read (leading to hard-to-debug bugs), this could be seen as a "safer" version of #read for some use-cases.

I didn't try to add a lazy reading function as there would be too many interpretations of what reading lazily even means depending on the use-case.

There's also a small optimization for IO::Memory (not benchmarked).

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add some specs for this new method.

end
end

def read_greedy(slice : Bytes) : Int32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: I doubt this optimization is actually necessary. I'd rather keep it out unless there is a proven effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add methods for filling a buffer from an IO greedily/lazily

3 participants