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

Make String#freeze spec-compliant #2160

Merged
merged 2 commits into from
Jun 28, 2024
Merged

Make String#freeze spec-compliant #2160

merged 2 commits into from
Jun 28, 2024

Conversation

seven1m
Copy link
Member

@seven1m seven1m commented Jun 28, 2024

#217

Today I learned:

'foo'.freeze.equal?('foo'.freeze) # => true

Interesting to note that it only seems to apply to string literals and doesn't work if you set a variable first:

s = 'foo'
s.freeze.equal?('foo'.freeze) # => false

(Good thing too, because I have no idea how we'd do that with the compiler! 😅)

@herwinw
Copy link
Member

herwinw commented Jun 28, 2024

(Good thing too, because I have no idea how we'd do that with the compiler! 😅)

Add a hashmap with the frozen strings, in case you freeze a variable that contains a string, look the actual value up in the vector, add it if it doesn't exist, and assign the address of the StringObject from the map to the variable.
I don't think this would be very good for your performance though.

This makes it easier to debug the generated cpp.
@seven1m
Copy link
Member Author

seven1m commented Jun 28, 2024

This was really easy thanks to the work in #2087. 🤗

@seven1m seven1m merged commit 944c1e7 into master Jun 28, 2024
15 checks passed
@seven1m seven1m deleted the string-freeze branch June 28, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants