Skip to content

Commit

Permalink
Refactor Crystal::System.retry_with_buffer calling #to_slice (#14614
Browse files Browse the repository at this point in the history
)

This is a trivial refactor, moving the call to `StaticArray#to_slice` out of the loop. On repeat iterations `buf` is a `Slice` so `#to_slice` is actually a no-op.
  • Loading branch information
straight-shoota authored Jun 11, 2024
1 parent 4c1f81b commit 5fd4595
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/crystal/system/unix.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
module Crystal::System
def self.retry_with_buffer(function_name, max_buffer, &)
initial_buf = uninitialized UInt8[1024]
buf = initial_buf
buf = initial_buf.to_slice

while (ret = yield buf.to_slice) != 0
while (ret = yield buf) != 0
case ret
when LibC::ENOENT, LibC::ESRCH, LibC::EBADF, LibC::EPERM
return nil
Expand Down

0 comments on commit 5fd4595

Please sign in to comment.