Skip to content

Commit

Permalink
Cache table in PrimTranslateStringWithTableNode
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Oct 22, 2021
1 parent 4c32242 commit 424b091
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,37 @@ protected static final long doLongMinValue(@SuppressWarnings("unused") final Obj
@SqueakPrimitive(names = "primitiveTranslateStringWithTable")
public abstract static class PrimTranslateStringWithTableNode extends AbstractPrimitiveNode implements QuinaryPrimitiveFallback {

@Specialization(guards = {"start >= 1", "string.isByteType()", "stop <= string.getByteLength()", "table.isByteType()", "table.getByteLength() >= 256"})
@Specialization(guards = {"start >= 1", "string.isByteType()", "stop <= string.getByteLength()", "table == cachedTable"}, limit = "1")
protected static final Object doNativeObjectCachedTable(final Object receiver, final NativeObject string, final long start, final long stop,
@SuppressWarnings("unused") final NativeObject table,
@Cached("byteTableOrNull(table)") final NativeObject cachedTable) {
return doNativeObject(receiver, string, start, stop, cachedTable);
}

protected static final NativeObject byteTableOrNull(final NativeObject table) {
return table.isByteType() && table.getByteLength() >= 256 ? table : null;
}

@Specialization(guards = {"start >= 1", "string.isByteType()", "stop <= string.getByteLength()", "table.isByteType()", "table.getByteLength() >= 256"}, replaces = "doNativeObjectCachedTable")
protected static final Object doNativeObject(final Object receiver, final NativeObject string, final long start, final long stop, final NativeObject table) {
for (long i = start - 1; i < stop; i++) {
string.setByte(i, table.getByte(string.getByteUnsigned(i)));
}
return receiver;
}

@Specialization(guards = {"start >= 1", "string.isByteType()", "stop <= string.getByteLength()", "table.isIntType()", "table.getIntLength() >= 256"})
@Specialization(guards = {"start >= 1", "string.isByteType()", "stop <= string.getByteLength()", "table == cachedTable"}, limit = "1")
protected static final Object doNativeObjectIntTableCached(final Object receiver, final NativeObject string, final long start, final long stop,
@SuppressWarnings("unused") final NativeObject table,
@Cached("intTableOrNull(table)") final NativeObject cachedTable) {
return doNativeObjectIntTable(receiver, string, start, stop, cachedTable);
}

protected static final NativeObject intTableOrNull(final NativeObject table) {
return table.isIntType() && table.getIntLength() >= 256 ? table : null;
}

@Specialization(guards = {"start >= 1", "string.isByteType()", "stop <= string.getByteLength()", "table.isIntType()", "table.getIntLength() >= 256"}, replaces = "doNativeObjectIntTableCached")
protected static final Object doNativeObjectIntTable(final Object receiver, final NativeObject string, final long start, final long stop,
final NativeObject table) {
for (long i = start - 1; i < stop; i++) {
Expand Down

0 comments on commit 424b091

Please sign in to comment.