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

Avoid double file buffering #13780

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
2 changes: 1 addition & 1 deletion src/crystal/system/unix/getrandom.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Crystal::System::Random
return unless urandom.info.type.character_device?

urandom.close_on_exec = true
urandom.sync = true # don't buffer bytes
urandom.read_buffering = false # don't buffer bytes
Copy link
Member

Choose a reason for hiding this comment

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

For context: sync controls write buffering, which is completely irrelevant here. read_buffering is used to control read buffering.

@@urandom = urandom
end
end
Expand Down
2 changes: 2 additions & 0 deletions src/digest/digest.cr
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ abstract class Digest
# Reads the file's content and updates the digest with it.
def file(file_name : Path | String) : self
File.open(file_name) do |io|
# `#update` works with big buffers so there's no need for additional read buffering in the file
io.read_buffering = false
carlhoerberg marked this conversation as resolved.
Show resolved Hide resolved
self << io
end
end
Expand Down
2 changes: 2 additions & 0 deletions src/file.cr
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,10 @@ class File < IO::FileDescriptor
open(filename, mode, perm, encoding: encoding, invalid: invalid) do |file|
case content
when Bytes
file.sync = true
file.write(content)
when IO
file.sync = true
IO.copy(content, file)
else
file.print(content)
Expand Down