Skip to content

Commit

Permalink
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -389,9 +389,9 @@ public static abstract class StringChrAtPrimitiveNode extends RubiniusPrimitiveN

public StringChrAtPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
stringByteSubstringNode = StringPrimitiveNodesFactory.StringByteSubstringPrimitiveNodeFactory.create(getContext(), getSourceSection(), new RubyNode[] {});
}

@TruffleBoundary
@Specialization
public Object stringChrAt(VirtualFrame frame, DynamicObject string, int byteIndex) {
// Taken from Rubinius's Character::create_from.
@@ -404,7 +404,7 @@ public Object stringChrAt(VirtualFrame frame, DynamicObject string, int byteInde

final int p = bytes.getBegin() + byteIndex;
final int end = bytes.getBegin() + bytes.getRealSize();
final int c = StringSupport.preciseLength(bytes.getEncoding(), bytes.getUnsafeBytes(), p, end);
final int c = preciseLength(bytes, p, end);

if (! StringSupport.MBCLEN_CHARFOUND_P(c)) {
return nil();
@@ -415,20 +415,14 @@ public Object stringChrAt(VirtualFrame frame, DynamicObject string, int byteInde
return nil();
}

if (stringByteSubstringNode == null) {
CompilerDirectives.transferToInterpreter();

stringByteSubstringNode = insert(
StringPrimitiveNodesFactory.StringByteSubstringPrimitiveNodeFactory.create(
getContext(),
getSourceSection(),
new RubyNode[]{})
);
}

return stringByteSubstringNode.stringByteSubstring(frame, string, byteIndex, n);
}

@TruffleBoundary
private int preciseLength(final ByteList bytes, final int p, final int end) {
return StringSupport.preciseLength(bytes.getEncoding(), bytes.getUnsafeBytes(), p, end);
}

}

@RubiniusPrimitive(name = "string_compare_substring")

0 comments on commit 1164b0a

Please sign in to comment.