Skip to content

Commit

Permalink
[Truffle] Don't calculate the entire byte[] when fetching a single byte.
Browse files Browse the repository at this point in the history
The original approach works well when String#getbyte is called multiple times on the same string, since the rope pays the cost to calculate the array once and then can do quick access. However, this approach fell apart miserably when single byte access is performed over large ropes with sparse byte[]. As an example, pr-zlib does this frequently in its pure Ruby implementation of zlib.
nirvdrum committed Mar 28, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent dd1552e commit 893d2e5
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
@@ -653,7 +653,7 @@ public int getByte(Rope rope, int index) {
@Specialization(guards = "rope.getRawBytes() == null")
@TruffleBoundary
public int getByteSlow(Rope rope, int index) {
return rope.getBytes()[index] & 0xff;
return rope.get(index) & 0xff;
}

}

0 comments on commit 893d2e5

Please sign in to comment.