-
Notifications
You must be signed in to change notification settings - Fork 199
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
Get tests passing with frozen-string-literals enabled. #354
Conversation
@@ -237,7 +237,7 @@ def coerce_encoding(string) | |||
end | |||
|
|||
def clear_buffer | |||
@buffer = '' | |||
@buffer = ''.dup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use String.new
for these to avoid the extra allocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've recently discovered via @koic that Ruby isn't quite consistent with String.new
. String.new.encoding
is ASCII-8BIT
, whereas String.new('').encoding
(which doesn't avoid the extra allocation) is UTF-8
.
I'm happy to change the PR to use String.new('')
- I presume UTF-8 is the preferred encoding? - I've just found that some library maintainers (particularly Rails) prefer dup
.
Please do so. |
Fails:
|
Yeah, I noticed that too :( There are PRs (for both 1.4.x and master branches) for frozen string literals in racc pending, though they've been dormant for a little while. I'm going to try to help get their builds passing when I have a spare moment, but that's probably not in the next 24 hours or so. |
Hi all, just coming back to this PR after several months, and with a couple of thoughts:
I'm happy to re-jig this PR to take the latter approach if that's desired? Would be great to get this merged in, rather than just waiting hopefully for a new racc release. |
Ping @tenderlove?
Sure, we can even do both. |
@whitequark I submitted a new PR with the pragma comments. This way at least things aren't reliant on dependencies (and I'm sure @tenderlove is either busy enough, or hopefully enjoying a bit of a break). So, I figure this PR can be closed, but possibly revisited later if people are particularly keen to use the |
These changes ensure that all string literals can be frozen (as per the optional feature in MRI 2.3 and onwards). I would recommend adding the following to your
.travis.yml
file to ensure regressions aren't introduced:This will add the flag when the tests are run on MRI 2.4 or newer (while the feature was introduced in 2.3, it doesn't seem to work reliably until 2.4).