Skip to content
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

Make IO::Buffered#buffer_size= idempotent #14855

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions spec/std/io/buffered_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ describe "IO::Buffered" do
end
end

it "can set buffer_size to the same value after first use" do
io = BufferedWrapper.new(IO::Memory.new("hello\r\nworld\n"))
io.buffer_size = 16_384
io.gets

io.buffer_size = 16_384
io.buffer_size.should eq(16_384)
end

it "does gets" do
io = BufferedWrapper.new(IO::Memory.new("hello\r\nworld\n"))
io.gets.should eq("hello")
Expand Down
2 changes: 1 addition & 1 deletion src/io/buffered.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module IO::Buffered
# Set the buffer size of both the read and write buffer
# Cannot be changed after any of the buffers have been allocated
def buffer_size=(value)
if @in_buffer || @out_buffer
if (@in_buffer || @out_buffer) && (buffer_size != value)
raise ArgumentError.new("Cannot change buffer_size after buffers have been allocated")
end
@buffer_size = value
Expand Down
Loading