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

Remove string allocation from GC_set_warn_proc #11729

Merged
merged 2 commits into from
Jan 12, 2022
Merged
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
8 changes: 5 additions & 3 deletions src/gc/boehm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ module GC
# By default the GC warns on big allocations/reallocations. This
# is of limited use and pollutes program output with warnings.
LibGC.set_warn_proc ->(msg, v) do
format_string = String.new(msg)
unless format_string.starts_with?("GC Warning: Repeated allocation of very large block")
LibC.printf format_string, v
start = "GC Warning: Repeated allocation of very large block"
# This implements `String#starts_with?` without allocating a `String` (#11728)
format_string = Slice.new(msg, Math.min(LibC.strlen(msg), start.bytesize))
unless format_string == start.to_slice
LibC.printf msg, v
end
end
end
Expand Down