Make Symbol#to_s return frozen string.

Monkey-patch Symbol#to_s to return a frozen (immutable) string instead
of a mutable string.

This should reduce string allocations, and thereby reduce memory usage
and garbage collector pressure, but it may be incompatible with
libraries that expect Symbol#to_s to return a mutable string.

https://bugs.ruby-lang.org/issues/16150
https://github.com/Shopify/symbol-fstring
This commit is contained in:
evazion
2021-12-14 17:03:54 -06:00
parent 4e730a145d
commit 67b96135dd

View File

@@ -62,3 +62,10 @@ end
class String
include Danbooru::Extensions::String
end
# Make Symbol#to_s return a frozen string. This reduces allocations, but may be
# incompatible with some libraries.
#
# https://bugs.ruby-lang.org/issues/16150
# https://github.com/Shopify/symbol-fstring
Symbol.alias_method(:to_s, :name)