Skip to content

Commit

Permalink
[Truffle] Switched to optimized RopeNodes.GetByteNode for the `string…
Browse files Browse the repository at this point in the history
…_rindex` primitive (part deux).
nirvdrum committed Mar 28, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 893d2e5 commit fa67889
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1302,11 +1302,13 @@ public DynamicObject stringResizeCapacity(DynamicObject string, int capacity) {
@RubiniusPrimitive(name = "string_rindex", lowerFixnumParameters = 1)
public static abstract class StringRindexPrimitiveNode extends RubiniusPrimitiveArrayArgumentsNode {

@Child private RopeNodes.GetByteNode getByteNode;
@Child private RopeNodes.GetByteNode patternGetByteNode;
@Child private RopeNodes.GetByteNode stringGetByteNode;

public StringRindexPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
getByteNode = RopeNodes.GetByteNode.create(context, sourceSection);
patternGetByteNode = RopeNodes.GetByteNode.create(context, sourceSection);
stringGetByteNode = RopeNodes.GetByteNode.create(context, sourceSection);
}

@Specialization(guards = "isRubyString(pattern)")
@@ -1335,10 +1337,10 @@ public Object stringRindex(DynamicObject string, DynamicObject pattern, int star
}

case 1: {
final int matcher = getByteNode.executeGetByte(patternRope, 0);
final int matcher = patternGetByteNode.executeGetByte(patternRope, 0);

while (pos >= 0) {
if (stringRope.get(pos) == matcher) {
if (stringGetByteNode.executeGetByte(stringRope, pos) == matcher) {
return pos;
}

0 comments on commit fa67889

Please sign in to comment.