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

Commits on Apr 24, 2018

  1. Copy the full SHA
    80a3e1b View commit details
  2. Deprecation.

    headius committed Apr 24, 2018
    Copy the full SHA
    d56fca0 View commit details
  3. Copy the full SHA
    c90308b View commit details
  4. Copy the full SHA
    a44cdc8 View commit details
11 changes: 7 additions & 4 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -3941,7 +3941,10 @@ public RubyArray split(ThreadContext context, IRubyObject arg0, IRubyObject arg1
if (lim <= 0) {
return splitCommon(context, arg0, false, lim, 1, true);
} else {
if (lim == 1) return value.getRealSize() == 0 ? context.runtime.newArray() : context.runtime.newArray(this);
if (lim == 1) {
Ruby runtime = context.runtime;
return value.getRealSize() == 0 ? runtime.newArray() : runtime.newArray(this.strDup(runtime));
}
return splitCommon(context, arg0, true, lim, 1, true);
}
}
@@ -4620,7 +4623,7 @@ public IRubyObject partition(ThreadContext context, IRubyObject arg, Block block

private RubyArray partitionMismatch(Ruby runtime) {
final Encoding enc = getEncoding();
return RubyArray.newArrayMayCopy(runtime, this, newEmptyString(runtime, enc), newEmptyString(runtime, enc));
return RubyArray.newArrayMayCopy(runtime, this.strDup(runtime), newEmptyString(runtime, enc), newEmptyString(runtime, enc));
}

@JRubyMethod(name = "rpartition", reads = BACKREF, writes = BACKREF)
@@ -4649,7 +4652,7 @@ public IRubyObject rpartition(ThreadContext context, IRubyObject arg) {

private IRubyObject rpartitionMismatch(Ruby runtime) {
final Encoding enc = getEncoding();
return RubyArray.newArray(runtime, new IRubyObject[]{newEmptyString(runtime, enc), newEmptyString(runtime, enc), this});
return RubyArray.newArray(runtime, new IRubyObject[]{newEmptyString(runtime, enc), newEmptyString(runtime, enc), this.strDup(runtime)});
}

/** rb_str_chop / rb_str_chop_bang
@@ -5317,7 +5320,7 @@ private IRubyObject trTrans19(ThreadContext context, IRubyObject src, IRubyObjec
RubyString srcStr = src.convertToString();

if (value.getRealSize() == 0) return context.nil;
if (replList.getRealSize() == 0) return delete_bang19(context, src);
if (replList.getRealSize() == 0) return delete_bang(context, src);

CodeRangeable ret = StringSupport.trTransHelper(context.runtime, this, srcStr, replStr, sflag);
return (ret == null) ? context.nil : (IRubyObject) ret;
22 changes: 12 additions & 10 deletions core/src/main/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
@@ -500,20 +500,19 @@ public IRubyObject getbyte(ThreadContext context) {
return context.runtime.newFixnum(c);
}

private RubyString strioSubstr(Ruby runtime, int pos, int len) {
private RubyString strioSubstr(Ruby runtime, int pos, int len, Encoding enc) {
StringIOData ptr = this.ptr;

synchronized (ptr) {
final RubyString string = ptr.string;
final ByteList stringByteList = string.getByteList();
final byte[] stringBytes = stringByteList.getUnsafeBytes();
final Encoding enc = ptr.enc;
int rlen = string.size() - pos;

if (len > rlen) len = rlen;
if (len < 0) len = 0;

if (len == 0) return RubyString.newEmptyString(runtime);
if (len == 0) return RubyString.newEmptyString(runtime, enc);
return RubyString.newStringShared(runtime, stringBytes, stringByteList.getBegin() + pos, len, enc);
}
}
@@ -589,7 +588,7 @@ public IRubyObject gets(ThreadContext context, IRubyObject[] args) {
@Override
public IRubyObject getline(ThreadContext context, StringIO self, IRubyObject rs, int limit, boolean chomp, Block block) {
if (limit == 0) {
return RubyString.newEmptyString(context.runtime);
return RubyString.newEmptyString(context.runtime, self.ptr.enc);
}

IRubyObject result = self.getline(context, rs, limit, chomp);
@@ -650,6 +649,7 @@ private IRubyObject getline(ThreadContext context, final IRubyObject rs, int lim
}

StringIOData ptr = this.ptr;
Encoding enc = ptr.enc;

synchronized (ptr) {
final ByteList string = ptr.string.getByteList();
@@ -667,7 +667,7 @@ private IRubyObject getline(ThreadContext context, final IRubyObject rs, int lim
if (chomp) {
w = chompNewlineWidth(stringBytes, s, e);
}
str = strioSubstr(runtime, ptr.pos, e - s - w);
str = strioSubstr(runtime, ptr.pos, e - s - w, enc);
} else if ((n = ((RubyString) rs).size()) == 0) {
// this is not an exact port; the original confused me
// in MRI, the next loop appears to have a complicated boolean to determine the index, but in actuality
@@ -700,15 +700,15 @@ else if (stringBytes[p] == '\r' && p < e && stringBytes[p + 1] == '\n') {
if (w == 0 && chomp) {
w = chompNewlineWidth(stringBytes, s, e);
}
str = strioSubstr(runtime, s - begin, e - s - w);
str = strioSubstr(runtime, s - begin, e - s - w, enc);
} else if (n == 1) {
RubyString strStr = (RubyString) rs;
ByteList strByteList = strStr.getByteList();
if ((p = StringSupport.memchr(stringBytes, s, strByteList.get(0), e - s)) != -1) {
e = p + 1;
w = (chomp ? ((p > s && stringBytes[p-1] == '\r')?1:0) + 1 : 0);
}
str = strioSubstr(runtime, ptr.pos, e - s - w);
str = strioSubstr(runtime, ptr.pos, e - s - w, enc);
} else {
if (n < e - s) {
RubyString rsStr = (RubyString) rs;
@@ -723,7 +723,7 @@ else if (stringBytes[p] == '\r' && p < e && stringBytes[p + 1] == '\n') {
e = s + pos + n;
}
}
str = strioSubstr(runtime, ptr.pos, e - s - w);
str = strioSubstr(runtime, ptr.pos, e - s - w, enc);
}
ptr.pos = e - begin;
ptr.lineno++;
@@ -862,11 +862,13 @@ public IRubyObject read(ThreadContext context, IRubyObject[] args) {
case 0:
len = ptr.string.size();
if (len <= ptr.pos) {
Encoding enc = binary ? ASCIIEncoding.INSTANCE : ptr.enc;
if (str.isNil()) {
str = runtime.newString();
} else {
((RubyString) str).resize(0);
}
((RubyString) str).setEncoding(enc);
return str;
} else {
len -= ptr.pos;
@@ -877,8 +879,8 @@ public IRubyObject read(ThreadContext context, IRubyObject[] args) {
}

if (str.isNil()) {
string = strioSubstr(runtime, ptr.pos, len);
if (binary) string.setEncoding(ASCIIEncoding.INSTANCE);
Encoding enc = binary ? ASCIIEncoding.INSTANCE : ptr.enc;
string = strioSubstr(runtime, ptr.pos, len, enc);
} else {
string = (RubyString) str;
int rest = ptr.string.size() - ptr.pos;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
@@ -2051,7 +2051,7 @@ public static CodeRangeable trTransHelper(CodeRangeable self, CodeRangeable srcS
}
}

if (cr == CR_VALID) {
if (cr == CR_VALID && enc.isAsciiCompatible()) {
cr = CR_7BIT;
}
self.modifyAndKeepCodeRange();