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: b3d136733b88
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0a399baa0e3b
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Nov 9, 2014

  1. Propagate coderange from StrNode -> StringLiteral and use it when bui…

    …lding compound strings. Fixes bug9882
    cheald committed Nov 9, 2014
    Copy the full SHA
    1899c26 View commit details
  2. Merge pull request #2162 from cheald/string_literal_coderange

    Propagate coderange from StrNode -> StringLiteral
    headius committed Nov 9, 2014
    Copy the full SHA
    0a399ba View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -3290,7 +3290,7 @@ public Operand buildSplat(SplatNode splatNode, IRScope s) {
}

public Operand buildStr(StrNode strNode, IRScope s) {
return copyAndReturnValue(s, new StringLiteral(strNode.getValue()));
return copyAndReturnValue(s, new StringLiteral(strNode.getValue(), strNode.getCodeRange()));
}

private Operand buildSuperInstr(IRScope s, Operand block, Operand[] args, int linenumber) {
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@ public Instr clone(CloneInfo ii) {
return new BuildCompoundStringInstr(ii.getRenamedVariable(result), newPieces, encoding);
}

public boolean isSameEncoding(StringLiteral str) {
return str.bytelist.getEncoding() == encoding;
public boolean isSameEncodingAndCodeRange(RubyString str, StringLiteral newStr) {
return newStr.bytelist.getEncoding() == encoding && newStr.getCodeRange() == str.getCodeRange();
}

public RubyString[] retrievePieces(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
@@ -97,11 +97,12 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
bytes.setEncoding(encoding);
RubyString str = RubyString.newStringShared(context.runtime, bytes, StringSupport.CR_7BIT);
for (Operand p : pieces) {
if ((p instanceof StringLiteral) && (isSameEncoding((StringLiteral)p))) {
if ((p instanceof StringLiteral) && (isSameEncodingAndCodeRange(str, (StringLiteral)p))) {
str.getByteList().append(((StringLiteral)p).bytelist);
str.setCodeRange(str.scanForCodeRange());
} else {
IRubyObject pval = (IRubyObject)p.retrieve(context, self, currScope, currDynScope, temp);
str.append19(pval);
IRubyObject pval = (IRubyObject)p.retrieve(context, self, currScope, currDynScope, temp);
str.append19(pval);
}
}

12 changes: 11 additions & 1 deletion core/src/main/java/org/jruby/ir/operands/StringLiteral.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

import java.nio.charset.UnsupportedCharsetException;
import java.util.List;
@@ -25,11 +26,17 @@ public class StringLiteral extends Operand {

final public ByteList bytelist;
final public String string;
final public int coderange;

public StringLiteral(ByteList val) {
this(val, StringSupport.CR_7BIT);
}

public StringLiteral(ByteList val, int coderange) {
super(OperandType.STRING_LITERAL);

bytelist = val;
this.coderange = coderange;
String stringTemp;
try {
stringTemp = Helpers.byteListToString(bytelist);
@@ -43,11 +50,12 @@ public StringLiteral(String s) {
this(s, ByteList.create(s));
}

private StringLiteral(String string, ByteList byteList ) {
private StringLiteral(String string, ByteList byteList) {
super(OperandType.STRING_LITERAL);

this.bytelist = byteList;
this.string = string;
this.coderange = StringSupport.CR_7BIT;
}

@Override
@@ -98,4 +106,6 @@ public ByteList getByteList() {
public String getString() {
return string;
}

public int getCodeRange() { return coderange; }
}