Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 82a62275015a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fd8c61e8aec8
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Apr 3, 2015

  1. Completed String#setbyte.

    nirvdrum committed Apr 3, 2015
    Copy the full SHA
    f978838 View commit details
  2. Copy the full SHA
    8261119 View commit details
  3. [Truffle] Dup the string when initializing from another string.

    We can only share the underlying byte list if we also dup it when we need to.  We currently don't track share status, so we can't reliably do that. The safe solution is to eagerly dup, which provides correctness at the cost of performance.
    nirvdrum committed Apr 3, 2015
    Copy the full SHA
    38c1be6 View commit details
  4. Copy the full SHA
    fd8c61e View commit details
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -3274,10 +3274,12 @@ public IRubyObject getbyte(ThreadContext context, IRubyObject index) {

@JRubyMethod
public IRubyObject setbyte(ThreadContext context, IRubyObject index, IRubyObject val) {
modifyAndKeepCodeRange();
int i = RubyNumeric.num2int(index);
int b = RubyNumeric.num2int(val);
value.getUnsafeBytes()[checkIndexForRef(i, value.getRealSize())] = (byte)b;
int normalizedIndex = checkIndexForRef(i, value.getRealSize());

modify19();
value.getUnsafeBytes()[normalizedIndex] = (byte)b;
return val;
}

1 change: 0 additions & 1 deletion spec/tags/ruby/core/string/setbyte_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/ruby/core/string/to_c_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/ruby/core/string/to_r_tags.txt

This file was deleted.

11 changes: 0 additions & 11 deletions spec/truffle/tags/core/string/setbyte_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1292,7 +1292,8 @@ public RubyString initialize(RubyString self, RubyString from) {
getContext().getCoreLibrary().frozenError(self.getLogicalClass().getName(), this));
}

self.set(from.getBytes());
// TODO (nirvdrum 03-Apr-15): Rather than dup every time, we should do CoW on String mutations.
self.set(from.getBytes().dup());
self.setCodeRange(from.getCodeRange());

return self;
@@ -1824,10 +1825,14 @@ public SetByteNode(SetByteNode prev) {
}

@Specialization
public Object setByte(RubyString string, int index, Object value) {
notDesignedForCompilation();
public int setByte(RubyString string, int index, int value) {
final int normalizedIndex = StringNodesHelper.checkIndexForRef(string, index, this);

string.modify();
string.clearCodeRange();
string.getByteList().getUnsafeBytes()[normalizedIndex] = (byte) value;

throw new UnsupportedOperationException("getbyte not implemented");
return value;
}
}

@@ -2577,6 +2582,30 @@ public static int checkIndex(RubyString string, int index, RubyNode node) {
return index;
}

public static int checkIndexForRef(RubyString string, int index, RubyNode node) {
final int length = string.getByteList().getRealSize();

if (index >= length) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
node.getContext().getCoreLibrary().indexError(String.format("index %d out of string", index), node));
}

if (index < 0) {
if (-index > length) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(
node.getContext().getCoreLibrary().indexError(String.format("index %d out of string", index), node));
}

index += length;
}

return index;
}

@TruffleBoundary
public static void replaceInternal(RubyString string, int start, int length, RubyString replacement) {
StringSupport.replaceInternal19(start, length, string, replacement);