Skip to content

Commit

Permalink
Showing 35 changed files with 280 additions and 261 deletions.
Original file line number Diff line number Diff line change
@@ -11,22 +11,23 @@
package org.jruby.truffle.nodes;

import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;

public abstract class StringCachingGuards {

public static ByteList privatizeByteList(DynamicObject string) {
if (RubyGuards.isRubyString(string)) {
return Layouts.STRING.getByteList(string).dup();
return StringOperations.getByteList(string).dup();
} else {
return null;
}
}

public static boolean byteListsEqual(DynamicObject string, ByteList byteList) {
if (RubyGuards.isRubyString(string)) {
return Layouts.STRING.getByteList(string).equal(byteList);
return StringOperations.getByteList(string).equal(byteList);
} else {
return false;
}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;

@NodeChild(value="child", type=RubyNode.class)
@@ -36,7 +37,7 @@ protected DynamicObject toSymbolSymbol(DynamicObject symbol) {

@Specialization(guards = "isRubyString(string)")
protected DynamicObject toSymbolString(DynamicObject string) {
return getSymbol(Layouts.STRING.getByteList(string));
return getSymbol(StringOperations.getByteList(string));
}

@Specialization
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;

@CoreClass(name = "BasicObject")
@@ -145,7 +146,7 @@ public InstanceEvalNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(string)")
public Object instanceEval(Object receiver, DynamicObject string, NotProvided block) {
return getContext().instanceEval(Layouts.STRING.getByteList(string), receiver, "(eval)", this);
return getContext().instanceEval(StringOperations.getByteList(string), receiver, "(eval)", this);
}

@Specialization(guards = "isRubyProc(block)")
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ public Object isCompatibleEncodingEncoding(DynamicObject first, DynamicObject se
@TruffleBoundary
@Specialization(guards = {"isRubyString(first)", "isRubyRegexp(second)"})
public Object isCompatibleStringRegexp(DynamicObject first, DynamicObject second) {
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(Layouts.STRING.getByteList(first).getEncoding(), Layouts.REGEXP.getRegex(second).getEncoding());
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(StringOperations.getByteList(first).getEncoding(), Layouts.REGEXP.getRegex(second).getEncoding());

if (compatibleEncoding != null) {
return getEncoding(compatibleEncoding);
@@ -151,7 +151,7 @@ public Object isCompatibleStringRegexp(DynamicObject first, DynamicObject second
@TruffleBoundary
@Specialization(guards = {"isRubyRegexp(first)", "isRubyString(second)"})
public Object isCompatibleRegexpString(DynamicObject first, DynamicObject second) {
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(Layouts.REGEXP.getRegex(first).getEncoding(), Layouts.STRING.getByteList(second).getEncoding());
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(Layouts.REGEXP.getRegex(first).getEncoding(), StringOperations.getByteList(second).getEncoding());

if (compatibleEncoding != null) {
return getEncoding(compatibleEncoding);
@@ -223,7 +223,7 @@ public Object isCompatibleSymbolSymbol(DynamicObject first, DynamicObject second
@TruffleBoundary
@Specialization(guards = {"isRubyString(first)", "isRubyEncoding(second)"})
public Object isCompatibleStringEncoding(DynamicObject first, DynamicObject second) {
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(Layouts.STRING.getByteList(first).getEncoding(), EncodingOperations.getEncoding(second));
final Encoding compatibleEncoding = org.jruby.RubyEncoding.areCompatible(StringOperations.getByteList(first).getEncoding(), EncodingOperations.getEncoding(second));

if (compatibleEncoding != null) {
return getEncoding(compatibleEncoding);
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.translator.BodyTranslator;
import org.jruby.util.RegexpOptions;
@@ -42,7 +43,7 @@ public Object execute(VirtualFrame frame) {

for (int n = 0; n < children.length; n++) {
final Object child = children[n].execute(frame);
strings[n] = org.jruby.RubyString.newString(getContext().getRuntime(), Layouts.STRING.getByteList((DynamicObject) toS.call(frame, child, "to_s", null)));
strings[n] = org.jruby.RubyString.newString(getContext().getRuntime(), StringOperations.getByteList((DynamicObject) toS.call(frame, child, "to_s", null)));
}

final org.jruby.RubyString preprocessed = org.jruby.RubyRegexp.preprocessDRegexp(getContext().getRuntime(), strings, options);
Original file line number Diff line number Diff line change
@@ -661,7 +661,7 @@ public Object evalBadBinding(DynamicObject source, DynamicObject badBinding, Not

@TruffleBoundary
private Object doEval(DynamicObject source, DynamicObject binding, String filename, boolean ownScopeForAssignments) {
final Object result = getContext().eval(ParserContext.EVAL, Layouts.STRING.getByteList(source), binding, ownScopeForAssignments, filename, this);
final Object result = getContext().eval(ParserContext.EVAL, StringOperations.getByteList(source), binding, ownScopeForAssignments, filename, this);
assert result != null;
return result;
}
@@ -1963,7 +1963,7 @@ public DynamicObject formatUncached(
throw handleException(e);
}

return finishFormat(Layouts.STRING.getByteList(format), result);
return finishFormat(StringOperations.getByteList(format), result);
}

private RuntimeException handleException(PackException exception) {
@@ -2022,7 +2022,7 @@ protected CallTarget compileFormat(DynamicObject format) {
assert RubyGuards.isRubyString(format);

try {
return new FormatParser(getContext()).parse(Layouts.STRING.getByteList(format));
return new FormatParser(getContext()).parse(StringOperations.getByteList(format));
} catch (FormatException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(e.getMessage(), this));
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ public static void updateCharOffset(DynamicObject matchData) {
assert RubyGuards.isRubyMatchData(matchData);
if (Layouts.MATCH_DATA.getCharOffsetUpdated(matchData)) return;

ByteList value = Layouts.STRING.getByteList(Layouts.MATCH_DATA.getSource(matchData));
ByteList value = StringOperations.getByteList(Layouts.MATCH_DATA.getSource(matchData));
Encoding enc = value.getEncoding();

if (Layouts.MATCH_DATA.getRegion(matchData) == null) {
@@ -247,7 +247,7 @@ public Object getIndexSymbol(DynamicObject matchData, DynamicObject index, NotPr
@Specialization(guards = "isRubyString(index)")
public Object getIndexString(DynamicObject matchData, DynamicObject index, NotProvided length) {
try {
ByteList value = Layouts.STRING.getByteList(index);
ByteList value = StringOperations.getByteList(index);
final int i = Layouts.REGEXP.getRegex(Layouts.MATCH_DATA.getRegexp(matchData)).nameToBackrefNumber(value.getUnsafeBytes(), value.getBegin(), value.getBegin() + value.getRealSize(), Layouts.MATCH_DATA.getRegion(matchData));

return getIndex(matchData, i, NotProvided.INSTANCE);
@@ -455,7 +455,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization
public DynamicObject toS(DynamicObject matchData) {
final ByteList bytes = Layouts.STRING.getByteList(Layouts.MATCH_DATA.getGlobal(matchData)).dup();
final ByteList bytes = StringOperations.getByteList(Layouts.MATCH_DATA.getGlobal(matchData)).dup();
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), bytes, StringSupport.CR_UNKNOWN, null);
}
}
Original file line number Diff line number Diff line change
@@ -649,7 +649,7 @@ private Object classEvalSource(DynamicObject module, DynamicObject code, String

final MaterializedFrame callerFrame = RubyCallStack.getCallerFrame(getContext())
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, false).materialize();
Encoding encoding = Layouts.STRING.getByteList(code).getEncoding();
Encoding encoding = StringOperations.getByteList(code).getEncoding();

CompilerDirectives.transferToInterpreter();
Source source = Source.fromText(code.toString(), file);
26 changes: 13 additions & 13 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ public abstract class RegexpNodes {
public static DynamicObject makeString(DynamicObject source, int start, int length) {
assert RubyGuards.isRubyString(source);

final ByteList bytes = new ByteList(Layouts.STRING.getByteList(source), start, length);
final ByteList bytes = new ByteList(StringOperations.getByteList(source), start, length);
final DynamicObject ret = Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(Layouts.BASIC_OBJECT.getLogicalClass(source)), bytes, StringSupport.CR_UNKNOWN, null);

Layouts.STRING.setCodeRange(ret, Layouts.STRING.getCodeRange(source));
@@ -89,7 +89,7 @@ public static Object matchCommon(DynamicObject regexp, DynamicObject source, boo
assert RubyGuards.isRubyRegexp(regexp);
assert RubyGuards.isRubyString(source);

final ByteList sourceByteList = Layouts.STRING.getByteList(source);
final ByteList sourceByteList = StringOperations.getByteList(source);

final ByteList bl = Layouts.REGEXP.getSource(regexp);
final Encoding enc = checkEncoding(regexp, StringOperations.getCodeRangeable(source), true);
@@ -107,7 +107,7 @@ public static Object matchCommon(DynamicObject regexp, DynamicObject source, boo
assert RubyGuards.isRubyRegexp(regexp);
assert RubyGuards.isRubyString(source);

final ByteList bytes = Layouts.STRING.getByteList(source);
final ByteList bytes = StringOperations.getByteList(source);
final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(regexp)).getContext();

final Frame frame = RubyCallStack.getCallerFrame(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(regexp)).getContext()).getFrame(FrameInstance.FrameAccess.READ_WRITE, false);
@@ -220,14 +220,14 @@ public static DynamicObject gsub(DynamicObject regexp, DynamicObject string, Str

final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(regexp)).getContext();

final byte[] stringBytes = Layouts.STRING.getByteList(string).bytes();
final byte[] stringBytes = StringOperations.getByteList(string).bytes();

final Encoding encoding = Layouts.STRING.getByteList(string).getEncoding();
final Encoding encoding = StringOperations.getByteList(string).getEncoding();
final Matcher matcher = Layouts.REGEXP.getRegex(regexp).matcher(stringBytes);

int p = Layouts.STRING.getByteList(string).getBegin();
int p = StringOperations.getByteList(string).getBegin();
int end = 0;
int range = p + Layouts.STRING.getByteList(string).getRealSize();
int range = p + StringOperations.getByteList(string).getRealSize();
int lastMatchEnd = 0;

// We only ever care about the entire matched string, not each of the matched parts, so we can hard-code the index.
@@ -253,7 +253,7 @@ public static DynamicObject gsub(DynamicObject regexp, DynamicObject string, Str
builder.append(StandardCharsets.UTF_8.decode(ByteBuffer.wrap(replacement.getBytes(StandardCharsets.UTF_8))));

lastMatchEnd = regionEnd;
end = StringSupport.positionEndForScan(Layouts.STRING.getByteList(string), matcher, encoding, p, range);
end = StringSupport.positionEndForScan(StringOperations.getByteList(string), matcher, encoding, p, range);
}

return Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(context.getCoreLibrary().getStringClass()), StringOperations.encodeByteList(builder.toString(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
@@ -266,12 +266,12 @@ public static DynamicObject[] split(DynamicObject regexp, final DynamicObject st

final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(regexp)).getContext();

final ByteList bytes = Layouts.STRING.getByteList(string);
final ByteList bytes = StringOperations.getByteList(string);
final byte[] byteArray = bytes.bytes();
final int begin = bytes.getBegin();
final int len = bytes.getRealSize();
final int range = begin + len;
final Encoding encoding = Layouts.STRING.getByteList(string).getEncoding();
final Encoding encoding = StringOperations.getByteList(string).getEncoding();
final Matcher matcher = Layouts.REGEXP.getRegex(regexp).matcher(byteArray);

final ArrayList<DynamicObject> strings = new ArrayList<>();
@@ -521,7 +521,7 @@ public EscapeNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization(guards = "isRubyString(pattern)")
public DynamicObject escape(DynamicObject pattern) {
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(org.jruby.RubyRegexp.quote19(new ByteList(Layouts.STRING.getByteList(pattern)), true).toString(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringOperations.encodeByteList(org.jruby.RubyRegexp.quote19(new ByteList(StringOperations.getByteList(pattern)), true).toString(), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
}

}
@@ -570,8 +570,8 @@ public QuoteNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization(guards = "isRubyString(raw)")
public DynamicObject quoteString(DynamicObject raw) {
boolean isAsciiOnly = Layouts.STRING.getByteList(raw).getEncoding().isAsciiCompatible() && StringOperations.scanForCodeRange(raw) == CR_7BIT;
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), org.jruby.RubyRegexp.quote19(Layouts.STRING.getByteList(raw), isAsciiOnly), StringSupport.CR_UNKNOWN, null);
boolean isAsciiOnly = StringOperations.getByteList(raw).getEncoding().isAsciiCompatible() && StringOperations.scanForCodeRange(raw) == CR_7BIT;
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), org.jruby.RubyRegexp.quote19(StringOperations.getByteList(raw), isAsciiOnly), StringSupport.CR_UNKNOWN, null);
}

@Specialization(guards = "isRubySymbol(raw)")
Original file line number Diff line number Diff line change
@@ -22,12 +22,12 @@ public class StringGuards {

public static boolean isSingleByteOptimizable(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return StringSupport.isSingleByteOptimizable(StringOperations.getCodeRangeable(string), Layouts.STRING.getByteList(string).getEncoding());
return StringSupport.isSingleByteOptimizable(StringOperations.getCodeRangeable(string), StringOperations.getByteList(string).getEncoding());
}

public static boolean isAsciiCompatible(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return Layouts.STRING.getByteList(string).getEncoding().isAsciiCompatible();
return StringOperations.getByteList(string).getEncoding().isAsciiCompatible();
}

public static boolean isSingleByteOptimizableOrAsciiOnly(DynamicObject string) {
@@ -38,7 +38,7 @@ public static boolean isSingleByteOptimizableOrAsciiOnly(DynamicObject string) {

public static boolean isSingleByte(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return Layouts.STRING.getByteList(string).getEncoding().isSingleByte();
return StringOperations.getByteList(string).getEncoding().isSingleByte();
}

public static boolean isValidOr7BitEncoding(DynamicObject string) {
@@ -48,11 +48,11 @@ public static boolean isValidOr7BitEncoding(DynamicObject string) {

public static boolean isFixedWidthEncoding(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return Layouts.STRING.getByteList(string).getEncoding().isFixedWidth();
return StringOperations.getByteList(string).getEncoding().isFixedWidth();
}

public static boolean isValidUtf8(DynamicObject string) {
assert RubyGuards.isRubyString(string);
return StringOperations.isCodeRangeValid(string) && Layouts.STRING.getByteList(string).getEncoding() instanceof UTF8Encoding;
return StringOperations.isCodeRangeValid(string) && StringOperations.getByteList(string).getEncoding() instanceof UTF8Encoding;
}
}
214 changes: 107 additions & 107 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -199,7 +199,7 @@ public DumpStringNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject dumpString(DynamicObject string) {
final StringBuilder builder = new StringBuilder();

final ByteList byteList = Layouts.STRING.getByteList(string);
final ByteList byteList = StringOperations.getByteList(string);

for (int i = 0; i < byteList.length(); i++) {
builder.append(String.format("\\x%02x", byteList.get(i)));
Original file line number Diff line number Diff line change
@@ -2487,7 +2487,7 @@ public DynamicObject packUncached(
throw handleException(e);
}

return finishPack(Layouts.STRING.getByteList(format), result);
return finishPack(StringOperations.getByteList(format), result);
}

private RuntimeException handleException(PackException exception) {
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.nodes.methods.DeclarationContext;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.methods.InternalMethod;

@@ -44,7 +45,7 @@ public CachedDispatchNode(
if (RubyGuards.isRubySymbol(cachedName)) {
cachedNameAsSymbol = (DynamicObject) cachedName;
} else if (RubyGuards.isRubyString(cachedName)) {
cachedNameAsSymbol = context.getSymbol(Layouts.STRING.getByteList((DynamicObject) cachedName));
cachedNameAsSymbol = context.getSymbol(StringOperations.getByteList((DynamicObject) cachedName));
} else if (cachedName instanceof String) {
cachedNameAsSymbol = context.getSymbol((String) cachedName);
} else {
@@ -72,7 +73,7 @@ protected final boolean guardName(Object methodName) {
// TODO(CS, 11-Jan-15) this just repeats the above guard...
return cachedName == methodName;
} else if (RubyGuards.isRubyString(cachedName)) {
return (RubyGuards.isRubyString(methodName)) && Layouts.STRING.getByteList((DynamicObject) cachedName).equal(Layouts.STRING.getByteList((DynamicObject) methodName));
return (RubyGuards.isRubyString(methodName)) && StringOperations.getByteList((DynamicObject) cachedName).equal(StringOperations.getByteList((DynamicObject) methodName));
} else {
throw new UnsupportedOperationException();
}
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import org.jruby.truffle.nodes.core.CoreMethod;
import org.jruby.truffle.nodes.core.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.layouts.ext.DigestLayoutImpl;
import org.jruby.util.ByteList;
@@ -146,7 +147,7 @@ public UpdateNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization(guards = "isRubyString(message)")
public DynamicObject update(DynamicObject digestObject, DynamicObject message) {
final ByteList bytes = Layouts.STRING.getByteList(message);
final ByteList bytes = StringOperations.getByteList(message);
DigestLayoutImpl.INSTANCE.getDigest(digestObject).update(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
return digestObject;
}
@@ -221,7 +222,7 @@ public BubbleBabbleNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization(guards = "isRubyString(message)")
public DynamicObject bubblebabble(DynamicObject message) {
final ByteList byteList = Layouts.STRING.getByteList(message);
final ByteList byteList = StringOperations.getByteList(message);
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), BubbleBabble.bubblebabble(byteList.unsafeBytes(), byteList.begin(), byteList.length()), StringSupport.CR_UNKNOWN, null);
}

Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.jruby.truffle.nodes.core.CoreMethod;
import org.jruby.truffle.nodes.core.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.object.ObjectGraph;

@@ -69,7 +70,7 @@ public int memsizeOfHash(DynamicObject object) {

@Specialization(guards = "isRubyString(object)")
public int memsizeOfString(DynamicObject object) {
return 1 + object.getShape().getPropertyListInternal(false).size() + Layouts.STRING.getByteList(object).getRealSize();
return 1 + object.getShape().getPropertyListInternal(false).size() + StringOperations.getByteList(object).getRealSize();
}

@Specialization(guards = "isRubyMatchData(object)")
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;
@@ -47,7 +48,7 @@ public int crc32(NotProvided message, NotProvided initial) {
@TruffleBoundary
@Specialization(guards = "isRubyString(message)")
public long crc32(DynamicObject message, NotProvided initial) {
final ByteList bytes = Layouts.STRING.getByteList(message);
final ByteList bytes = StringOperations.getByteList(message);
final CRC32 crc32 = new CRC32();
crc32.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
return crc32.getValue();
@@ -61,7 +62,7 @@ public long crc32(DynamicObject message, int initial) {
@TruffleBoundary
@Specialization(guards = "isRubyString(message)")
public long crc32(DynamicObject message, long initial) {
final ByteList bytes = Layouts.STRING.getByteList(message);
final ByteList bytes = StringOperations.getByteList(message);
final CRC32 crc32 = new CRC32();
crc32.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
return JZlib.crc32_combine(initial, crc32.getValue(), bytes.length());
@@ -89,7 +90,7 @@ public DeflateNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject deflate(DynamicObject message, int level) {
final Deflater deflater = new Deflater(level);

final ByteList messageBytes = Layouts.STRING.getByteList(message);
final ByteList messageBytes = StringOperations.getByteList(message);
deflater.setInput(messageBytes.unsafeBytes(), messageBytes.begin(), messageBytes.length());

final ByteList outputBytes = new ByteList(BUFFER_SIZE);
@@ -121,7 +122,7 @@ public InflateNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject inflate(DynamicObject message) {
final Inflater inflater = new Inflater();

final ByteList messageBytes = Layouts.STRING.getByteList(message);
final ByteList messageBytes = StringOperations.getByteList(message);
inflater.setInput(messageBytes.unsafeBytes(), messageBytes.begin(), messageBytes.length());

final ByteList outputBytes = new ByteList(BUFFER_SIZE);
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.adapaters.InputStreamAdapter;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;
@@ -201,7 +202,7 @@ private Object doParse(DynamicObject parserObject, DynamicObject yaml, DynamicOb

private StreamReader readerFor(DynamicObject yaml) {
if (RubyGuards.isRubyString(yaml)) {
ByteList byteList = Layouts.STRING.getByteList(yaml);
ByteList byteList = StringOperations.getByteList(yaml);
Encoding enc = byteList.getEncoding();

// if not unicode, transcode to UTF8
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
import org.jruby.truffle.nodes.objects.WriteInstanceVariableNode;
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.methods.InternalMethod;

@@ -165,7 +166,7 @@ public InteropStringIsBoxed(RubyContext context, SourceSection sourceSection) {
@Override
public Object execute(VirtualFrame frame) {
Object o = ForeignAccessArguments.getReceiver(frame.getArguments());
return RubyGuards.isRubyString(o) && Layouts.STRING.getByteList((DynamicObject) o).length() == 1;
return RubyGuards.isRubyString(o) && StringOperations.getByteList((DynamicObject) o).length() == 1;
}
}

@@ -178,7 +179,7 @@ public InteropStringUnboxNode(RubyContext context, SourceSection sourceSection)

@Override
public Object execute(VirtualFrame frame) {
return Layouts.STRING.getByteList((DynamicObject) ForeignAccessArguments.getReceiver(frame.getArguments())).get(0);
return StringOperations.getByteList((DynamicObject) ForeignAccessArguments.getReceiver(frame.getArguments())).get(0);
}
}

@@ -273,10 +274,10 @@ public Object execute(VirtualFrame frame) {
if (RubyGuards.isRubyString(ForeignAccessArguments.getReceiver(frame.getArguments()))) {
final DynamicObject string = (DynamicObject) ForeignAccessArguments.getReceiver(frame.getArguments());
final int index = (int) ForeignAccessArguments.getArgument(frame.getArguments(), labelIndex);
if (index >= Layouts.STRING.getByteList(string).length()) {
if (index >= StringOperations.getByteList(string).length()) {
return 0;
} else {
return (byte) Layouts.STRING.getByteList(string).get(index);
return (byte) StringOperations.getByteList(string).get(index);
}
} else {
CompilerDirectives.transferToInterpreter();
Original file line number Diff line number Diff line change
@@ -52,11 +52,11 @@ public PrependNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyString(string)")
public DynamicObject prepend(DynamicObject bytes, DynamicObject string) {
final int prependLength = Layouts.STRING.getByteList(string).getUnsafeBytes().length;
final int prependLength = StringOperations.getByteList(string).getUnsafeBytes().length;
final int originalLength = Layouts.BYTE_ARRAY.getBytes(bytes).getUnsafeBytes().length;
final int newLength = prependLength + originalLength;
final byte[] prependedBytes = new byte[newLength];
System.arraycopy(Layouts.STRING.getByteList(string).getUnsafeBytes(), 0, prependedBytes, 0, prependLength);
System.arraycopy(StringOperations.getByteList(string).getUnsafeBytes(), 0, prependedBytes, 0, prependLength);
System.arraycopy(Layouts.BYTE_ARRAY.getBytes(bytes).getUnsafeBytes(), 0, prependedBytes, prependLength, originalLength);
return ByteArrayNodes.createByteArray(getContext().getCoreLibrary().getByteArrayClass(), new ByteList(prependedBytes));
}
@@ -106,7 +106,7 @@ public LocateNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isRubyString(pattern)")
public Object getByte(DynamicObject bytes, DynamicObject pattern, int start, int length) {
final int index = new ByteList(Layouts.BYTE_ARRAY.getBytes(bytes), start, length).indexOf(Layouts.STRING.getByteList(pattern));
final int index = new ByteList(Layouts.BYTE_ARRAY.getBytes(bytes), start, length).indexOf(StringOperations.getByteList(pattern));

if (index == -1) {
return nil();
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ public Object encodingConverterPrimitiveConvert(DynamicObject encodingConverter,
StringOperations.modify(source);
StringOperations.clearCodeRange(source);

return primitiveConvertHelper(encodingConverter, Layouts.STRING.getByteList(source), source, target, offset, size, options);
return primitiveConvertHelper(encodingConverter, StringOperations.getByteList(source), source, target, offset, size, options);
}

@TruffleBoundary
@@ -95,7 +95,7 @@ private Object primitiveConvertHelper(DynamicObject encodingConverter, ByteList
StringOperations.modify(target);
StringOperations.clearCodeRange(target);

final ByteList outBytes = Layouts.STRING.getByteList(target);
final ByteList outBytes = StringOperations.getByteList(target);

final Ptr inPtr = new Ptr();
final Ptr outPtr = new Ptr();
@@ -109,8 +109,8 @@ private Object primitiveConvertHelper(DynamicObject encodingConverter, ByteList
size = 16; // in MRI, this is RSTRING_EMBED_LEN_MAX

if (nonNullSourceProfile.profile(nonNullSource)) {
if (size < Layouts.STRING.getByteList(source).getRealSize()) {
size = Layouts.STRING.getByteList(source).getRealSize();
if (size < StringOperations.getByteList(source).getRealSize()) {
size = StringOperations.getByteList(source).getRealSize();
}
}
}
@@ -146,8 +146,8 @@ private Object primitiveConvertHelper(DynamicObject encodingConverter, ByteList
outBytes.setRealSize(outPtr.p - outBytes.begin());

if (nonNullSourceProfile.profile(nonNullSource)) {
Layouts.STRING.getByteList(source).setRealSize(inBytes.getRealSize() - (inPtr.p - inBytes.getBegin()));
Layouts.STRING.getByteList(source).setBegin(inPtr.p);
StringOperations.getByteList(source).setRealSize(inBytes.getRealSize() - (inPtr.p - inBytes.getBegin()));
StringOperations.getByteList(source).setBegin(inPtr.p);
}

if (growOutputBuffer && res == EConvResult.DestinationBufferFull) {
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.core.EncodingNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;

/**
@@ -30,7 +31,7 @@ public EncodingGetObjectEncodingNode(RubyContext context, SourceSection sourceSe

@Specialization(guards = "isRubyString(string)")
public DynamicObject encodingGetObjectEncodingString(DynamicObject string) {
return EncodingNodes.getEncoding(Layouts.STRING.getByteList(string).getEncoding());
return EncodingNodes.getEncoding(StringOperations.getByteList(string).getEncoding());
}

@Specialization(guards = "isRubySymbol(symbol)")
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@
import org.jruby.truffle.nodes.core.ExceptionNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;

@@ -86,7 +87,7 @@ public IOBufferUnshiftPrimitiveNode(RubyContext context, SourceSection sourceSec
public int unshift(VirtualFrame frame, DynamicObject ioBuffer, DynamicObject string, int startPosition) {
Layouts.IO_BUFFER.setWriteSynced(ioBuffer, false);

final ByteList byteList = Layouts.STRING.getByteList(string);
final ByteList byteList = StringOperations.getByteList(string);
int stringSize = byteList.realSize() - startPosition;
final int usedSpace = Layouts.IO_BUFFER.getUsed(ioBuffer);
final int availableSpace = IOBUFFER_SIZE - usedSpace;
Original file line number Diff line number Diff line change
@@ -211,8 +211,8 @@ public IOFNMatchPrimitiveNode(RubyContext context, SourceSection sourceSection)
@TruffleBoundary
@Specialization(guards = {"isRubyString(pattern)", "isRubyString(path)"})
public boolean fnmatch(DynamicObject pattern, DynamicObject path, int flags) {
final ByteList patternBytes = Layouts.STRING.getByteList(pattern);
final ByteList pathBytes = Layouts.STRING.getByteList(path);
final ByteList patternBytes = StringOperations.getByteList(pattern);
final ByteList pathBytes = StringOperations.getByteList(path);
return Dir.fnmatch(patternBytes.getUnsafeBytes(),
patternBytes.getBegin(),
patternBytes.getBegin() + patternBytes.getRealSize(),
@@ -418,7 +418,7 @@ public IOWritePrimitiveNode(RubyContext context, SourceSection sourceSection) {
public int write(DynamicObject file, DynamicObject string) {
final int fd = Layouts.IO.getDescriptor(file);

final ByteList byteList = Layouts.STRING.getByteList(string);
final ByteList byteList = StringOperations.getByteList(string);

if (getContext().getDebugStandardOut() != null && fd == STDOUT) {
getContext().getDebugStandardOut().write(byteList.unsafeBytes(), byteList.begin(), byteList.length());
Original file line number Diff line number Diff line change
@@ -310,7 +310,7 @@ public PointerWriteStringPrimitiveNode(RubyContext context, SourceSection source

@Specialization(guards = "isRubyString(string)")
public DynamicObject address(DynamicObject pointer, DynamicObject string, int maxLength) {
final ByteList bytes = Layouts.STRING.getByteList(string);
final ByteList bytes = StringOperations.getByteList(string);
final int length = Math.min(bytes.length(), maxLength);
Layouts.POINTER.getPointer(pointer).put(0, bytes.unsafeBytes(), bytes.begin(), length);
return pointer;
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public AccessNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(path)")
public int access(DynamicObject path, int mode) {
final String pathString = RubyEncoding.decodeUTF8(Layouts.STRING.getByteList(path).getUnsafeBytes(), Layouts.STRING.getByteList(path).getBegin(), Layouts.STRING.getByteList(path).getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringOperations.getByteList(path).getUnsafeBytes(), StringOperations.getByteList(path).getBegin(), StringOperations.getByteList(path).getRealSize());
return posix().access(pathString, mode);
}

@@ -175,7 +175,7 @@ public GetenvNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(name)")
public DynamicObject getenv(DynamicObject name) {
final String nameString = RubyEncoding.decodeUTF8(Layouts.STRING.getByteList(name).getUnsafeBytes(), Layouts.STRING.getByteList(name).getBegin(), Layouts.STRING.getByteList(name).getRealSize());
final String nameString = RubyEncoding.decodeUTF8(StringOperations.getByteList(name).getUnsafeBytes(), StringOperations.getByteList(name).getBegin(), StringOperations.getByteList(name).getRealSize());

Object result = posix().getenv(nameString);

@@ -326,7 +326,7 @@ public ReadlinkNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = {"isRubyString(path)", "isRubyPointer(pointer)"})
public int readlink(DynamicObject path, DynamicObject pointer, int bufsize) {
final ByteList byteList = Layouts.STRING.getByteList(path);
final ByteList byteList = StringOperations.getByteList(path);
final String pathString = RubyEncoding.decodeUTF8(byteList.unsafeBytes(), byteList.begin(), byteList.length());

final int result = posix().readlink(pathString, Layouts.POINTER.getPointer(pointer), bufsize);
@@ -350,8 +350,8 @@ public SetenvNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = { "isRubyString(name)", "isRubyString(value)" })
public int setenv(DynamicObject name, DynamicObject value, int overwrite) {
final String nameString = RubyEncoding.decodeUTF8(Layouts.STRING.getByteList(name).getUnsafeBytes(), Layouts.STRING.getByteList(name).getBegin(), Layouts.STRING.getByteList(name).getRealSize());
final String valueString = RubyEncoding.decodeUTF8(Layouts.STRING.getByteList(value).getUnsafeBytes(), Layouts.STRING.getByteList(value).getBegin(), Layouts.STRING.getByteList(value).getRealSize());
final String nameString = RubyEncoding.decodeUTF8(StringOperations.getByteList(name).getUnsafeBytes(), StringOperations.getByteList(name).getBegin(), StringOperations.getByteList(name).getRealSize());
final String valueString = RubyEncoding.decodeUTF8(StringOperations.getByteList(value).getUnsafeBytes(), StringOperations.getByteList(value).getBegin(), StringOperations.getByteList(value).getRealSize());

return posix().setenv(nameString, valueString, overwrite);
}
@@ -368,8 +368,8 @@ public LinkNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = {"isRubyString(path)", "isRubyString(other)"})
public int link(DynamicObject path, DynamicObject other) {
final String pathString = RubyEncoding.decodeUTF8(Layouts.STRING.getByteList(path).getUnsafeBytes(), Layouts.STRING.getByteList(path).getBegin(), Layouts.STRING.getByteList(path).getRealSize());
final String otherString = RubyEncoding.decodeUTF8(Layouts.STRING.getByteList(other).getUnsafeBytes(), Layouts.STRING.getByteList(other).getBegin(), Layouts.STRING.getByteList(other).getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringOperations.getByteList(path).getUnsafeBytes(), StringOperations.getByteList(path).getBegin(), StringOperations.getByteList(path).getRealSize());
final String otherString = RubyEncoding.decodeUTF8(StringOperations.getByteList(other).getUnsafeBytes(), StringOperations.getByteList(other).getBegin(), StringOperations.getByteList(other).getRealSize());
return posix().link(pathString, otherString);
}

@@ -385,7 +385,7 @@ public UnlinkNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(path)")
public int unlink(DynamicObject path) {
final ByteList byteList = Layouts.STRING.getByteList(path);
final ByteList byteList = StringOperations.getByteList(path);
return posix().unlink(RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize()));
}

@@ -415,7 +415,7 @@ public UnsetenvNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(name)")
public int unsetenv(DynamicObject name) {
final ByteList byteList = Layouts.STRING.getByteList(name);
final ByteList byteList = StringOperations.getByteList(name);
final String nameString = RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());

return posix().unsetenv(nameString);
@@ -433,7 +433,7 @@ public UtimesNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = {"isRubyString(path)", "isRubyPointer(pointer)"})
public int utimes(DynamicObject path, DynamicObject pointer) {
final ByteList byteList = Layouts.STRING.getByteList(path);
final ByteList byteList = StringOperations.getByteList(path);
final String pathString = RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());

final int result = posix().utimes(pathString, Layouts.POINTER.getPointer(pointer));
@@ -687,8 +687,8 @@ public RenameNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = {"isRubyString(path)", "isRubyString(other)"})
public int rename(DynamicObject path, DynamicObject other) {
final String pathString = RubyEncoding.decodeUTF8(Layouts.STRING.getByteList(path).getUnsafeBytes(), Layouts.STRING.getByteList(path).getBegin(), Layouts.STRING.getByteList(path).getRealSize());
final String otherString = RubyEncoding.decodeUTF8(Layouts.STRING.getByteList(other).getUnsafeBytes(), Layouts.STRING.getByteList(other).getBegin(), Layouts.STRING.getByteList(other).getRealSize());
final String pathString = RubyEncoding.decodeUTF8(StringOperations.getByteList(path).getUnsafeBytes(), StringOperations.getByteList(path).getBegin(), StringOperations.getByteList(path).getRealSize());
final String otherString = RubyEncoding.decodeUTF8(StringOperations.getByteList(other).getUnsafeBytes(), StringOperations.getByteList(other).getBegin(), StringOperations.getByteList(other).getRealSize());
return posix().rename(pathString, otherString);
}

@@ -722,7 +722,7 @@ public DynamicObject getcwd(DynamicObject resultPath, int maxSize) {
// We just ignore maxSize - I think this is ok

final String path = getContext().getRuntime().getCurrentDirectory();
Layouts.STRING.getByteList(resultPath).replace(path.getBytes(StandardCharsets.UTF_8));
StringOperations.getByteList(resultPath).replace(path.getBytes(StandardCharsets.UTF_8));
return resultPath;
}

@@ -866,8 +866,8 @@ public int getaddrinfoNil(DynamicObject hostName, DynamicObject serviceName, Dyn
@Specialization(guards = {"isRubyString(hostName)", "isRubyString(serviceName)", "isRubyPointer(hintsPointer)", "isRubyPointer(resultsPointer)"})
public int getaddrinfoString(DynamicObject hostName, DynamicObject serviceName, DynamicObject hintsPointer, DynamicObject resultsPointer) {
return nativeSockets().getaddrinfo(
Layouts.STRING.getByteList(hostName),
Layouts.STRING.getByteList(serviceName),
StringOperations.getByteList(hostName),
StringOperations.getByteList(serviceName),
Layouts.POINTER.getPointer(hintsPointer),
Layouts.POINTER.getPointer(resultsPointer));
}
@@ -876,7 +876,7 @@ public int getaddrinfoString(DynamicObject hostName, DynamicObject serviceName,
@Specialization(guards = {"isRubyString(hostName)", "isNil(serviceName)", "isRubyPointer(hintsPointer)", "isRubyPointer(resultsPointer)"})
public int getaddrinfo(DynamicObject hostName, DynamicObject serviceName, DynamicObject hintsPointer, DynamicObject resultsPointer) {
return nativeSockets().getaddrinfo(
Layouts.STRING.getByteList(hostName),
StringOperations.getByteList(hostName),
null,
Layouts.POINTER.getPointer(hintsPointer),
Layouts.POINTER.getPointer(resultsPointer));
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ public DynamicObject initializeAlreadyInitialized(DynamicObject regexp, DynamicO

@Specialization(guards = {"!isRegexpLiteral(regexp)", "!isInitialized(regexp)", "isRubyString(pattern)"})
public DynamicObject initialize(DynamicObject regexp, DynamicObject pattern, int options) {
RegexpNodes.initialize(regexp, this, Layouts.STRING.getByteList(pattern), options);
RegexpNodes.initialize(regexp, this, StringOperations.getByteList(pattern), options);
return regexp;
}

@@ -129,13 +129,13 @@ public Object searchRegionNotInitialized(DynamicObject regexp, DynamicObject str
public Object searchRegionInvalidEncoding(DynamicObject regexp, DynamicObject string, int start, int end, boolean forward) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(
String.format("invalid byte sequence in %s", Layouts.STRING.getByteList(string).getEncoding()), this));
String.format("invalid byte sequence in %s", StringOperations.getByteList(string).getEncoding()), this));
}

@TruffleBoundary
@Specialization(guards = {"isInitialized(regexp)", "isRubyString(string)", "isValidEncoding(string)"})
public Object searchRegion(DynamicObject regexp, DynamicObject string, int start, int end, boolean forward) {
final ByteList stringBl = Layouts.STRING.getByteList(string);
final ByteList stringBl = StringOperations.getByteList(string);
final ByteList bl = Layouts.REGEXP.getSource(regexp);
final Encoding enc = RegexpNodes.checkEncoding(regexp, StringOperations.getCodeRangeable(string), true);
final ByteList preprocessed = RegexpSupport.preprocess(getContext().getRuntime(), bl, enc, new Encoding[]{null}, RegexpSupport.ErrorMode.RAISE);
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode;
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNodeGen;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;

@@ -172,7 +173,7 @@ public StatStatPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@Specialization(guards = "isRubyString(path)")
public int stat(DynamicObject rubyStat, DynamicObject path) {
final FileStat stat = posix().allocateStat();
final ByteList byteList = Layouts.STRING.getByteList(path);
final ByteList byteList = StringOperations.getByteList(path);
final String pathString = RubyEncoding.decodeUTF8(byteList.getUnsafeBytes(), byteList.getBegin(), byteList.getRealSize());
final int code = posix().stat(pathString, stat);

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -211,7 +211,7 @@ public TimeStrftimePrimitiveNode(RubyContext context, SourceSection sourceSectio
public DynamicObject timeStrftime(DynamicObject time, DynamicObject format) {
final RubyDateFormatter rdf = getContext().getRuntime().getCurrentContext().getRubyDateFormatter();
// TODO CS 15-Feb-15 ok to just pass nanoseconds as 0?
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), rdf.formatToByteList(rdf.compilePattern(Layouts.STRING.getByteList(format), false), TimeNodes.getDateTime(time), 0, null), StringSupport.CR_UNKNOWN, null);
return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), rdf.formatToByteList(rdf.compilePattern(StringOperations.getByteList(format), false), TimeNodes.getDateTime(time), 0, null), StringSupport.CR_UNKNOWN, null);
}

}
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
import org.jruby.truffle.pack.nodes.PackNode;
import org.jruby.truffle.pack.runtime.exceptions.NoImplicitConversionException;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;

@@ -99,7 +100,7 @@ public ByteList toStringString(VirtualFrame frame, DynamicObject string) {
setTainted(frame);
}

return Layouts.STRING.getByteList(string);
return StringOperations.getByteList(string);
}

@Specialization(guards = "isRubyArray(array)")
@@ -116,7 +117,7 @@ public ByteList toString(VirtualFrame frame, DynamicObject array) {
setTainted(frame);
}

return Layouts.STRING.getByteList((DynamicObject) value);
return StringOperations.getByteList((DynamicObject) value);
}

CompilerDirectives.transferToInterpreter();
@@ -142,7 +143,7 @@ public ByteList toString(VirtualFrame frame, Object object) {
setTainted(frame);
}

return Layouts.STRING.getByteList((DynamicObject) value);
return StringOperations.getByteList((DynamicObject) value);
}

if (inspectOnConversionFailure) {
@@ -152,7 +153,7 @@ public ByteList toString(VirtualFrame frame, Object object) {
getEncapsulatingSourceSection(), new RubyNode[]{null}));
}

return Layouts.STRING.getByteList(inspectNode.toS(frame, object));
return StringOperations.getByteList(inspectNode.toS(frame, object));
}

CompilerDirectives.transferToInterpreter();
Original file line number Diff line number Diff line change
@@ -503,7 +503,7 @@ public IRubyObject toJRubyEncoding(DynamicObject encoding) {
public org.jruby.RubyString toJRubyString(DynamicObject string) {
assert RubyGuards.isRubyString(string);

final org.jruby.RubyString jrubyString = runtime.newString(Layouts.STRING.getByteList(string).dup());
final org.jruby.RubyString jrubyString = runtime.newString(StringOperations.getByteList(string).dup());

final Object tainted = string.get(Layouts.TAINTED_IDENTIFIER, Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getCoreLibrary().getNilObject());

Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.core.BasicForeignAccessFactory;
import org.jruby.truffle.runtime.core.HashForeignAccessFactory;
import org.jruby.truffle.runtime.core.StringForeignAccessFactory;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;

public class RubyObjectType extends ObjectType {
@@ -30,7 +31,7 @@ public String toString(DynamicObject object) {
final RubyContext context = getContext();

if (RubyGuards.isRubyString(object)) {
return Helpers.decodeByteList(context.getRuntime(), Layouts.STRING.getByteList(object));
return Helpers.decodeByteList(context.getRuntime(), StringOperations.getByteList(object));
} else if (RubyGuards.isRubySymbol(object)) {
return Layouts.SYMBOL.getString(object);
} else if (RubyGuards.isRubyException(object)) {
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public Encoding checkEncoding(CodeRangeable other) {

@Override
public ByteList getByteList() {
return Layouts.STRING.getByteList(string);
return StringOperations.getByteList(string);
}

}
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ public abstract class StringOperations {
// Since ByteList.toString does not decode properly
@CompilerDirectives.TruffleBoundary
public static String getString(DynamicObject string) {
return Helpers.decodeByteList(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getRuntime(), Layouts.STRING.getByteList(string));
return Helpers.decodeByteList(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getRuntime(), StringOperations.getByteList(string));
}

public static StringCodeRangeableWrapper getCodeRangeable(DynamicObject string) {
@@ -85,13 +85,13 @@ public static void keepCodeRange(DynamicObject string) {

public static void modify(DynamicObject string) {
// TODO (nirvdrum 16-Feb-15): This should check whether the underlying ByteList is being shared and copy if necessary.
Layouts.STRING.getByteList(string).invalidate();
StringOperations.getByteList(string).invalidate();
}

public static void modify(DynamicObject string, int length) {
// TODO (nirvdrum Jan. 13, 2015): This should check whether the underlying ByteList is being shared and copy if necessary.
Layouts.STRING.getByteList(string).ensure(length);
Layouts.STRING.getByteList(string).invalidate();
StringOperations.getByteList(string).ensure(length);
StringOperations.getByteList(string).invalidate();
}

public static void modifyAndKeepCodeRange(DynamicObject string) {
@@ -107,7 +107,7 @@ public static Encoding checkEncoding(DynamicObject string, CodeRangeable other)
if (encoding == null) {
throw Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getRuntime().newEncodingCompatibilityError(
String.format("incompatible character encodings: %s and %s",
Layouts.STRING.getByteList(string).getEncoding().toString(),
StringOperations.getByteList(string).getEncoding().toString(),
other.getByteList().getEncoding().toString()));
}

@@ -116,7 +116,7 @@ public static Encoding checkEncoding(DynamicObject string, CodeRangeable other)

@CompilerDirectives.TruffleBoundary
private static int slowCodeRangeScan(DynamicObject string) {
final ByteList byteList = Layouts.STRING.getByteList(string);
final ByteList byteList = StringOperations.getByteList(string);
return StringSupport.codeRangeScan(byteList.getEncoding(), byteList);
}

@@ -130,9 +130,9 @@ public static void forceEncoding(DynamicObject string, Encoding encoding) {
public static int length(DynamicObject string) {
if (CompilerDirectives.injectBranchProbability(
CompilerDirectives.FASTPATH_PROBABILITY,
StringSupport.isSingleByteOptimizable(getCodeRangeable(string), Layouts.STRING.getByteList(string).getEncoding()))) {
StringSupport.isSingleByteOptimizable(getCodeRangeable(string), StringOperations.getByteList(string).getEncoding()))) {

return Layouts.STRING.getByteList(string).getRealSize();
return StringOperations.getByteList(string).getRealSize();

} else {
return StringSupport.strLengthFromRubyString(getCodeRangeable(string));
@@ -149,7 +149,7 @@ public static int normalizeIndex(DynamicObject rubyString, int index) {

public static int clampExclusiveIndex(DynamicObject string, int index) {
assert RubyGuards.isRubyString(string);
return ArrayOperations.clampExclusiveIndex(Layouts.STRING.getByteList(string).length(), index);
return ArrayOperations.clampExclusiveIndex(StringOperations.getByteList(string).length(), index);
}

@CompilerDirectives.TruffleBoundary
@@ -159,7 +159,7 @@ public static Encoding checkEncoding(DynamicObject string, CodeRangeable other,
if (encoding == null) {
throw new RaiseException(
Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(string)).getContext().getCoreLibrary().encodingCompatibilityErrorIncompatible(
Layouts.STRING.getByteList(string).getEncoding().toString(),
StringOperations.getByteList(string).getEncoding().toString(),
other.getByteList().getEncoding().toString(),
node)
);
@@ -175,5 +175,9 @@ public static boolean singleByteOptimizable(DynamicObject string) {
public static ByteList encodeByteList(CharSequence value, Encoding encoding) {
return RubyString.encodeBytelist(value, encoding);
}

public static ByteList getByteList(DynamicObject object) {
return Layouts.STRING.getByteList(object);
}

}

0 comments on commit b6552a7

Please sign in to comment.