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

Commits on Feb 16, 2015

  1. Abstracted EncodingUtils.encCrStrBufCat to work with any CodeRangeabl…

    …e and EncodingUtils.strBufCat to work with any ByteListHolder.
    nirvdrum committed Feb 16, 2015
    Copy the full SHA
    92122e0 View commit details
  2. Copy the full SHA
    ffda39d View commit details
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/ByteListHolder.java
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@

public interface ByteListHolder {
public ByteList getByteList();
public void modify();
public void modify(int length);
public Encoding checkEncoding(ByteListHolder other);
}
22 changes: 13 additions & 9 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
@@ -38,7 +38,9 @@
import org.jruby.runtime.encoding.EncodingCapable;
import org.jruby.runtime.encoding.EncodingService;
import org.jruby.util.ByteList;
import org.jruby.util.ByteListHolder;
import org.jruby.util.CodeRangeSupport;
import org.jruby.util.CodeRangeable;
import org.jruby.util.StringSupport;
import org.jruby.util.TypeConverter;

@@ -1461,7 +1463,7 @@ public static void rbStrBufCat(Ruby runtime, RubyString str, ByteList ptr) {
// negative length check here, we shouldn't need
strBufCat(runtime, str, ptr);
}
public static void rbStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len) {
public static void rbStrBufCat(Ruby runtime, ByteListHolder str, byte[] ptrBytes, int ptr, int len) {
if (len == 0) return;
// negative length check here, we shouldn't need
strBufCat(runtime, str, ptrBytes, ptr, len);
@@ -1476,7 +1478,7 @@ public static void rbStrBufCat(Ruby runtime, ByteList str, byte[] ptrBytes, int
public static void strBufCat(Ruby runtime, RubyString str, ByteList ptr) {
strBufCat(runtime, str, ptr.getUnsafeBytes(), ptr.getBegin(), ptr.getRealSize());
}
public static void strBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len) {
public static void strBufCat(Ruby runtime, ByteListHolder str, byte[] ptrBytes, int ptr, int len) {
str.modify();
strBufCat(str.getByteList(), ptrBytes, ptr, len);
}
@@ -1508,16 +1510,16 @@ public static void encStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, i
}

// rb_enc_cr_str_buf_cat
public static void encCrStrBufCat(Ruby runtime, RubyString str, ByteList ptr, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
public static void encCrStrBufCat(Ruby runtime, CodeRangeable str, ByteList ptr, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
encCrStrBufCat(runtime, str, ptr.getUnsafeBytes(), ptr.getBegin(), ptr.getRealSize(), ptrEnc, ptr_cr, ptr_cr_ret);
}
public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes, int ptr, int len, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
Encoding strEnc = str.getEncoding();
public static void encCrStrBufCat(Ruby runtime, CodeRangeable str, byte[] ptrBytes, int ptr, int len, Encoding ptrEnc, int ptr_cr, int[] ptr_cr_ret) {
Encoding strEnc = str.getByteList().getEncoding();
Encoding resEnc;
int str_cr, res_cr;
boolean incompatible = false;

str_cr = str.size() > 0 ? str.getCodeRange() : StringSupport.CR_7BIT;
str_cr = str.getByteList().getRealSize() > 0 ? str.getCodeRange() : StringSupport.CR_7BIT;

if (strEnc == ptrEnc) {
if (str_cr == StringSupport.CR_UNKNOWN) {
@@ -1530,9 +1532,10 @@ public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes,
if (len == 0) {
return;
}
if (str.size() == 0) {
if (str.getByteList().getRealSize() == 0) {
rbStrBufCat(runtime, str, ptrBytes, ptr, len);
str.setEncodingAndCodeRange(ptrEnc, ptr_cr);
str.getByteList().setEncoding(ptrEnc);
str.setCodeRange(ptr_cr);
return;
}
incompatible = true;
@@ -1586,7 +1589,8 @@ public static void encCrStrBufCat(Ruby runtime, RubyString str, byte[] ptrBytes,
// MRI checks for len < 0 here, but I don't think that's possible for us

strBufCat(runtime, str, ptrBytes, ptr, len);
str.setEncodingAndCodeRange(resEnc, res_cr);
str.getByteList().setEncoding(resEnc);
str.setCodeRange(res_cr);
}

// econv_args
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/string/concat_tags.txt
Original file line number Diff line number Diff line change
@@ -5,9 +5,3 @@ fails:String#concat with Integer returns a ASCII-8BIT string if self is US-ASCII
fails:String#concat with Integer raises RangeError if the argument is an invalid codepoint for self's encoding
fails:String#concat with Integer raises RangeError if the argument is negative
fails:String#concat with Integer raises a RuntimeError when self is frozen
fails:String#concat when self is in an ASCII-incompatible encoding incompatible with the argument's encoding uses the argument's encoding if self is empty
fails:String#concat when self is in an ASCII-incompatible encoding incompatible with the argument's encoding raises Encoding::CompatibilityError if neither are empty
fails:String#concat when the argument is in an ASCII-incompatible encoding incompatible with self's encoding uses the argument's encoding if self is empty
fails:String#concat when the argument is in an ASCII-incompatible encoding incompatible with self's encoding raises Encoding::CompatibilityError if neither are empty
fails:String#concat when self and the argument are in different ASCII-compatible encodings uses the argument's encoding if self is ASCII-only
fails:String#concat when self and the argument are in different ASCII-compatible encodings raises Encoding::CompatibilityError if neither are ASCII-only
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/valid_encoding_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@
import org.jruby.util.ByteList;
import org.jruby.util.Pack;
import org.jruby.util.StringSupport;
import org.jruby.util.io.EncodingUtils;

import java.math.BigInteger;
import java.nio.ByteBuffer;
@@ -226,7 +227,23 @@ public RubyString concat(RubyString string, RubyString other) {
throw new RaiseException(getContext().getCoreLibrary().frozenError("String", this));
}

string.getBytes().append(other.getBytes());
final int codeRange = other.getCodeRange();
final int[] ptr_cr_ret = { codeRange };

try {
EncodingUtils.encCrStrBufCat(getContext().getRuntime(), string, other.getByteList(), other.getByteList().getEncoding(), codeRange, ptr_cr_ret);
} catch (org.jruby.exceptions.RaiseException e) {
if (e.getException().getMetaClass().equals(getContext().getRuntime().getEncodingCompatibilityError())) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(getContext().getCoreLibrary().encodingCompatibilityError(e.getException().message.asJavaString(), this));
}

throw e;
}

other.setCodeRange(ptr_cr_ret[0]);

return string;
}
}
Original file line number Diff line number Diff line change
@@ -205,6 +205,12 @@ public final void clearCodeRange() {
codeRange = StringSupport.CR_UNKNOWN;
}

@Override
public final void modify() {
// TODO (nirvdrum 16-Feb-15): This should check whether the underlying ByteList is being shared and copy if necessary.
bytes.invalidate();
}

@Override
public final void modify(int length) {
// TODO (nirvdrum Jan. 13, 2015): This should check whether the underlying ByteList is being shared and copy if necessary.