History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-1552
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: Kornelius Kalnbach
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

/o regexp modifier (Ruby compatibility)

Created: 11/Nov/07 01:44 AM   Updated: 22/Dec/07 06:26 AM
Component/s: Compiler, Parser, Core Classes/Modules
Affects Version/s: JRuby 1.1b1
Fix Version/s: JRuby 1.0.3, JRuby 1.1RC2

Time Tracking:
Not Specified

File Attachments: 1. Text File JRUBY-1552a.patch (3 kb)
2. Text File JRUBY-1552b.patch (2 kb)
3. Text File JRUBY-1552test.patch (0.4 kb)

Environment: Anywhere

Testcase included: yes


 Description  « Hide
Ruby regular expressions provide a /o option with the following meaning (from Pickaxe, forgive me):

o - Substitute Once.
Any #... substitutions in a particular regular expression literal will be performed just once, the first time it is evaluated. Otherwise, the substitutions will be performed every time the literal generates a Regexp object.

JRuby currently ignores the modifier, which results in lower performance when a library is counting on the feature. For example, CodeRay (http://coderay.rubyforge.org/) uses it heavily, and runs about 10,000 times slower with jruby 1.1b1.

Testing the feature is simple:

assert Array('a'..'z').map { |c| c.to_s/#{c}/o }.compact.size == 1



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Charles Oliver Nutter - 11/Nov/07 01:45 AM
This shouldn't be hard to fix for 1.1 and 1.0.3 (easy backport for the 1.0 interpreter).

Joshua Graham - 11/Nov/07 12:30 PM
Initial patch for compiler off mode.

Tested with:

jruby -C -e "10.times {|i| puts i.to_s/#{i}/o }"

Should now return:

0
nil
nil
nil
nil
nil
nil
nil
nil
nil


Joshua Graham - 11/Nov/07 12:37 PM
btw, patch for 1.1

Pretty much do the same thing as done to ASTInterpreter to EvaluationState in 1.0 (I don't have the source handy)


Joshua Graham - 16/Nov/07 02:42 AM
This alters the compiler to achieve the same end.

It lends from the optimisation in the ByteList processing RegExp which checks to see if it had already created a RegExp from the same ByteList.

In this alteration, we check to see if the source specified the /o flag. If it did, we store the first evaluation and then jump on subsequent evaluations, so the closure is, in effect, only evaluated once at runtime.


Joshua Graham - 16/Nov/07 03:00 PM
And an extra testRegexp.rb minirunit test to check behaviour (with and without /o flag)

Charles Oliver Nutter - 16/Nov/07 03:30 PM
Patches look good, thanks Josh! Fixed on trunk in 4952 and on 1.0 branch in 4953.