Skip to content

Commit 6ae852f

Browse files
committed
Turn ByteArrayNodes.LocateNode into a primitive for efficiency.
1 parent ca54fc6 commit 6ae852f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/java/org/truffleruby/core/support/ByteArrayNodes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import com.oracle.truffle.api.strings.TruffleString;
1616
import org.truffleruby.annotations.CoreMethod;
1717
import org.truffleruby.annotations.CoreModule;
18+
import org.truffleruby.annotations.Primitive;
1819
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
20+
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
1921
import org.truffleruby.core.encoding.TStringUtils;
2022
import org.truffleruby.core.klass.RubyClass;
2123
import org.truffleruby.core.string.RubyString;
@@ -151,8 +153,8 @@ protected Object fillFromPointer(
151153

152154
}
153155

154-
@CoreMethod(names = "locate", required = 3, lowerFixnum = { 2, 3 })
155-
public abstract static class LocateNode extends CoreMethodArrayArgumentsNode {
156+
@Primitive(name = "bytearray_locate", lowerFixnum = { 2, 3 })
157+
public abstract static class LocateNode extends PrimitiveArrayArgumentsNode {
156158

157159
@Specialization(
158160
guards = "isSingleBytePattern(patternTString, patternEncoding)", limit = "1")

src/main/ruby/truffleruby/core/io.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def discard(skip)
202202
# Returns the number of bytes to fetch from the buffer up-to-
203203
# and-including +pattern+. Returns +nil+ if pattern is not found.
204204
def find(pattern, discard = nil)
205-
if count = @storage.locate(pattern, @start, @used)
205+
if count = Primitive.bytearray_locate(@storage, pattern, @start, @used)
206206
count - @start
207207
end
208208
end

0 commit comments

Comments
 (0)