Skip to content

Commit

Permalink
No need to copy from io::memory
Browse files Browse the repository at this point in the history
  • Loading branch information
spuun committed Oct 24, 2024
1 parent e1177cc commit 0ef9c34
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mqtt/protocol/payload.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ module MQTT
if data = @data
io.write data
else
# try to copy if it's possible to "rewind"
if @io.io.is_a?(::IO::Memory | ::IO::FileDescriptor)
if io_mem = @io.io.as?(::IO::Memory)
io.write io_mem.to_slice
elsif @io.io.is_a?(::IO::FileDescriptor)
pos = @io.pos
copied = ::IO.copy(@io, io, bytesize)
raise "Failed to copy payload" if copied != bytesize
@io.pos = pos
else
# copy to memory and write
io.write to_slice
end
end
Expand Down

0 comments on commit 0ef9c34

Please sign in to comment.