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
StringScanner.new should use StringValue #696
Comments
Your variant is wrong because it fails specs where string is a subclass of String class. But this one works well: def initialize(string, dup=false) @string = string.to_str reset_state end After doing this, the bench with rubinius runs faster than with 1.9.2/1.8.7 |
Isn't MRI doing the same? |
In MRI 1.9.2 and 1.8.7:
|
Really, I don't know much about MRI. I just took your variant and ran specs) |
It seems there's a spec missing for StringScanner#string. Something like this:
|
How about this: http://gist.github.com/836007 |
Use coersion if possible in StringScanner. Closed by 7cbb344 |
According to the original C implementation, StringScanner.new does not copy the string, but only coerce it:
So, the method in lib/strscan.rb should be:
In addition, #string= and #concat should use StringValue to coerce the string. #concat may not need it since String#<< already uses StringValue, but it seems cleaner to apply it there, too.
The change speeds up this benchmark quite a bit:
Runs for minutes without the fix.
The text was updated successfully, but these errors were encountered: