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: f28bd50e26ce
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8d306f6a69bf
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 3, 2015

  1. Copy the full SHA
    54e6c03 View commit details
  2. Copy the full SHA
    8d306f6 View commit details
Showing with 32 additions and 1 deletion.
  1. +18 −0 spec/ruby/core/string/setbyte_spec.rb
  2. +14 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
18 changes: 18 additions & 0 deletions spec/ruby/core/string/setbyte_spec.rb
Original file line number Diff line number Diff line change
@@ -84,4 +84,22 @@
it "raises a TypeError unless the second argument is an Integer" do
lambda { "a".setbyte(0,'a') }.should raise_error(TypeError)
end

it "calls #to_int to convert the index" do
index = mock("setbyte index")
index.should_receive(:to_int).and_return(1)

str = "hat"
str.setbyte(index, "i".ord)
str.should == "hit"
end

it "calls to_int to convert the value" do
value = mock("setbyte value")
value.should_receive(:to_int).and_return("i".ord)

str = "hat"
str.setbyte(1, value)
str.should == "hit"
end
end
Original file line number Diff line number Diff line change
@@ -1814,7 +1814,12 @@ public RubyString scan(VirtualFrame frame, RubyString string, RubyRegexp regexp,
}

@CoreMethod(names = "setbyte", required = 2, raiseIfFrozenSelf = true)
public abstract static class SetByteNode extends CoreMethodNode {
@NodeChildren({
@NodeChild(value = "string"),
@NodeChild(value = "index"),
@NodeChild(value = "value")
})
public abstract static class SetByteNode extends RubyNode {

public SetByteNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@@ -1824,6 +1829,14 @@ public SetByteNode(SetByteNode prev) {
super(prev);
}

@CreateCast("index") public RubyNode coerceIndexToInt(RubyNode index) {
return new FixnumLowerNode(ToIntNodeFactory.create(getContext(), getSourceSection(), index));
}

@CreateCast("value") public RubyNode coerceValueToInt(RubyNode value) {
return new FixnumLowerNode(ToIntNodeFactory.create(getContext(), getSourceSection(), value));
}

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