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

Commits on Aug 23, 2017

  1. Copy the full SHA
    6267767 View commit details
  2. Copy the full SHA
    5d9d2d1 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyMatchData.java
Original file line number Diff line number Diff line change
@@ -308,7 +308,7 @@ private RubyRegexp getRegexp() {
}

private static RubyString makeShared(Ruby runtime, RubyString str, int index, int length) {
return str.makeShared19(runtime, index, length);
return str.makeShared(runtime, index, length);
}

private RubyArray match_array(Ruby runtime, int start) {
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyRegexp.java
Original file line number Diff line number Diff line change
@@ -1535,7 +1535,7 @@ public static IRubyObject nth_match(int nth, IRubyObject match) {

if (start == -1) return runtime.getNil();

RubyString str = m.str.makeShared19(runtime, m.str.getType(), start, end - start);
RubyString str = m.str.makeShared(runtime, start, end - start);
str.infectBy(m);
return str;
}
@@ -1557,7 +1557,7 @@ public static IRubyObject match_pre(IRubyObject match) {

Ruby runtime = m.getRuntime();
if (m.begin == -1) runtime.getNil();
return m.str.makeShared19(runtime, m.str.getType(), 0, m.begin).infectBy(m);
return m.str.makeShared(runtime, 0, m.begin).infectBy(m);
}

/** rb_reg_match_post
@@ -1570,7 +1570,7 @@ public static IRubyObject match_post(IRubyObject match) {

Ruby runtime = m.getRuntime();
if (m.begin == -1) return runtime.getNil();
return m.str.makeShared19(runtime, m.str.getType(), m.end, m.str.getByteList().getRealSize() - m.end).infectBy(m);
return m.str.makeShared(runtime, m.end, m.str.getByteList().getRealSize() - m.end).infectBy(m);
}

/** rb_reg_match_last
67 changes: 27 additions & 40 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -809,15 +809,16 @@ final RubyString strDup(Ruby runtime, RubyClass clazz) {

/* rb_str_subseq */
public final RubyString makeSharedString(Ruby runtime, int index, int len) {
return makeShared19(runtime, runtime.getString(), index, len);
return makeShared(runtime, runtime.getString(), value, index, len);
}

public RubyString makeSharedString19(Ruby runtime, int index, int len) {
return makeShared19(runtime, runtime.getString(), value, index, len);
@Deprecated
public final RubyString makeSharedString19(Ruby runtime, int index, int len) {
return makeShared(runtime, runtime.getString(), value, index, len);
}

public final RubyString makeShared(Ruby runtime, int index, int len) {
return makeShared19(runtime, getType(), index, len);
return makeShared(runtime, getType(), value, index, len);
}

public final RubyString makeShared(Ruby runtime, RubyClass meta, int index, int len) {
@@ -836,19 +837,21 @@ public final RubyString makeShared(Ruby runtime, RubyClass meta, int index, int
return shared;
}

@Deprecated
public final RubyString makeShared19(Ruby runtime, int index, int len) {
return makeShared19(runtime, value, index, len);
return makeShared(runtime, value, index, len);
}

@Deprecated
public final RubyString makeShared19(Ruby runtime, RubyClass meta, int index, int len) {
return makeShared19(runtime, meta, value, index, len);
return makeShared(runtime, meta, value, index, len);
}

private RubyString makeShared19(Ruby runtime, ByteList value, int index, int len) {
return makeShared19(runtime, getType(), value, index, len);
private RubyString makeShared(Ruby runtime, ByteList value, int index, int len) {
return makeShared(runtime, getType(), value, index, len);
}

private RubyString makeShared19(Ruby runtime, RubyClass meta, ByteList value, int index, int len) {
private RubyString makeShared(Ruby runtime, RubyClass meta, ByteList value, int index, int len) {
final RubyString shared;
Encoding enc = value.getEncoding();

@@ -2534,7 +2537,7 @@ private IRubyObject subBangIter(Ruby runtime, ThreadContext context, IRubyObject
final int mBeg = matcher.getBegin(), mEnd = matcher.getEnd();

final RubyString repl; final int tuFlags;
IRubyObject subStr = makeShared19(runtime, mBeg, mEnd - mBeg);
IRubyObject subStr = makeShared(runtime, mBeg, mEnd - mBeg);
if (hash == null) {
tuFlags = 0;
repl = objAsString(context, block.yield(context, subStr));
@@ -2728,7 +2731,7 @@ private IRubyObject gsubCommon19(ThreadContext context, Block block, RubyString
if (repl != null) { // string given
val = RubyRegexp.regsub19(context, repl, this, matcher, pattern);
} else {
final RubyString substr = makeShared19(runtime, begz, endz - begz);
final RubyString substr = makeShared(runtime, begz, endz - begz);
if (hash != null) { // hash given
val = objAsString(context, hash.op_aref(context, substr));
} else { // block given
@@ -2954,7 +2957,7 @@ public final IRubyObject substr(Ruby runtime, int beg, int len) {
}

int end = Math.min(length, beg + len);
return makeShared19(runtime, beg, end - beg);
return makeShared(runtime, beg, end - beg);
}

/* str_byte_substr */
@@ -2973,7 +2976,7 @@ private IRubyObject byteSubstr(Ruby runtime, int beg, int len) {
len = 0;
}

return makeShared19(runtime, beg, len);
return makeShared(runtime, beg, len);
}

/* str_byte_aref */
@@ -3040,7 +3043,7 @@ private IRubyObject multibyteSubstr19(Ruby runtime, Encoding enc, int len, int b
if (p == -1) return runtime.getNil();
while (len-- > 0 && (p = enc.prevCharHead(bytes, s, p, e)) != -1) {} // nothing
if (p == -1) return runtime.getNil();
return makeShared19(runtime, p - s, e - p);
return makeShared(runtime, p - s, e - p);
} else {
beg += StringSupport.strLengthFromRubyString(this, enc);
if (beg < 0) return runtime.getNil();
@@ -3069,7 +3072,7 @@ private IRubyObject multibyteSubstr19(Ruby runtime, Encoding enc, int len, int b
} else {
len = StringSupport.offset(enc, bytes, p, end, len);
}
return makeShared19(runtime, p - s, len);
return makeShared(runtime, p - s, len);
}

/* rb_str_splice */
@@ -3611,7 +3614,7 @@ private void populateCapturesForSplit(Ruby runtime, RubyArray result, RubyMatchD
for (int i = 1; i < match.numRegs(); i++) {
int beg = match.begin(i);
if (beg == -1) continue;
result.append(makeShared19(runtime, beg, match.end(i) - beg));
result.append(makeShared(runtime, beg, match.end(i) - beg));
}
}

@@ -3704,7 +3707,7 @@ private RubyArray regexSplit19(ThreadContext context, RubyRegexp pattern, boolea
result.append(newEmptyString(runtime, getMetaClass()).infectBy(this));
break;
} else if (lastNull) {
result.append(makeShared19(runtime, beg, StringSupport.length(enc, bytes, ptr + beg, ptr + len)));
result.append(makeShared(runtime, beg, StringSupport.length(enc, bytes, ptr + beg, ptr + len)));
beg = start;
} else {
if ((ptr + start) == ptr + len) {
@@ -3716,7 +3719,7 @@ private RubyArray regexSplit19(ThreadContext context, RubyRegexp pattern, boolea
continue;
}
} else {
result.append(makeShared19(runtime, beg, end - beg));
result.append(makeShared(runtime, beg, end - beg));
beg = match.end(0);
start = beg;
}
@@ -3771,7 +3774,7 @@ private RubyArray awkSplit19(boolean limit, int lim, int i) {
}
} else {
if (enc.isSpace(c)) {
result.append(makeShared19(runtime, b, e - b));
result.append(makeShared(runtime, b, e - b));
skip = true;
b = p - ptr;
if (limit) i++;
@@ -3781,7 +3784,7 @@ private RubyArray awkSplit19(boolean limit, int lim, int i) {
}
}

if (len > 0 && (limit || len > b || lim < 0)) result.append(makeShared19(runtime, b, len - b));
if (len > 0 && (limit || len > b || lim < 0)) result.append(makeShared(runtime, b, len - b));
return result;
}

@@ -3810,13 +3813,13 @@ private RubyArray stringSplit19(ThreadContext context, RubyString spat, boolean
p = t;
continue;
}
result.append(makeShared19(runtime, p, e - p));
result.append(makeShared(runtime, p, e - p));
p = e + pattern.getRealSize();
if (limit && lim <= ++i) break;
}

if (value.getRealSize() > 0 && (limit || value.getRealSize() > p || lim < 0)) {
result.append(makeShared19(runtime, p, value.getRealSize() - p));
result.append(makeShared(runtime, p, value.getRealSize() - p));
}

return result;
@@ -3887,22 +3890,6 @@ public IRubyObject scan(ThreadContext context, IRubyObject arg, Block block) {
return scan19(context, arg, block);
}

private IRubyObject populateCapturesForScan(Ruby runtime, Matcher matcher, int range, int tuFlags, boolean is19) {
Region region = matcher.getRegion();
RubyArray result = getRuntime().newArray(region.numRegs);
for (int i=1; i<region.numRegs; i++) {
int beg = region.beg[i];
if (beg == -1) {
result.append(runtime.getNil());
} else {
RubyString substr = is19 ? makeShared19(runtime, beg, region.end[i] - beg) : makeShared(runtime, beg, region.end[i] - beg);
substr.infectBy(tuFlags);
result.append(substr);
}
}
return result;
}

@JRubyMethod(name = "scan", reads = BACKREF, writes = BACKREF)
public IRubyObject scan19(ThreadContext context, IRubyObject pat, Block block) {
final RubyString str = this;
@@ -4271,9 +4258,9 @@ public IRubyObject partition(ThreadContext context, IRubyObject arg, Block block
}

return RubyArray.newArray(runtime, new IRubyObject[]{
makeShared19(runtime, 0, pos),
makeShared(runtime, 0, pos),
sep,
makeShared19(runtime, pos + sep.value.getRealSize(), value.getRealSize() - pos - sep.value.getRealSize())});
makeShared(runtime, pos + sep.value.getRealSize(), value.getRealSize() - pos - sep.value.getRealSize())});
}

private IRubyObject partitionMismatch(Ruby runtime) {
Original file line number Diff line number Diff line change
@@ -227,15 +227,15 @@ private IRubyObject extractRange(Ruby runtime, int beg, int end) {
int size = str.getByteList().getRealSize();
if (beg > size) return runtime.getNil();
if (end > size) end = size;
return str.makeSharedString19(runtime, beg, end - beg);
return str.makeSharedString(runtime, beg, end - beg);
}

private IRubyObject extractBegLen(Ruby runtime, int beg, int len) {
assert len >= 0;
int size = str.getByteList().getRealSize();
if (beg > size) return runtime.getNil();
if (beg + len > size) len = size - beg;
return str.makeSharedString19(runtime, beg, len);
return str.makeSharedString(runtime, beg, len);
}

ThreadLocal<Matcher> currentMatcher = new ThreadLocal<>();
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/io/PopenExecutor.java
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public static IRubyObject checkPipeCommand(ThreadContext context, IRubyObject fi
filenameByteList.getBegin() + filenameByteList.getRealSize(),
chlen,
filenameByteList.getEncoding()) == '|') {
return filenameStr.makeShared19(context.runtime, chlen[0], filenameByteList.length() - 1).infectBy(filenameOrCommand);
return filenameStr.makeShared(context.runtime, chlen[0], filenameByteList.length() - 1).infectBy(filenameOrCommand);
}
return context.nil;
}
1 change: 1 addition & 0 deletions lib/ruby/stdlib/jruby/core_ext/class.rb
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
#
class Class
JClass = java.lang.Class
private_constant :JClass

##
# Get an array of all known subclasses of this class. If recursive == true,
3 changes: 1 addition & 2 deletions lib/ruby/stdlib/jruby/core_ext/string.rb
Original file line number Diff line number Diff line change
@@ -2,14 +2,13 @@
require 'jruby'

class String
RubyString = org.jruby.RubyString

# Construct a new string with a buffer of the specified size. The buffer is
# filled with null bytes to start.
#
# May be useful in cases where you know how large a string will grow, and want
# to pre-allocate the buffer for that size.
def self.alloc(size)
RubyString.new_string_light(JRuby.runtime, size)
org.jruby.RubyString.new_string_light(JRuby.runtime, size)
end
end
6 changes: 3 additions & 3 deletions lib/ruby/stdlib/jruby/core_ext/thread.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'java'

class Thread
ThreadBean = java.lang.management.ManagementFactory.thread_mx_bean

# Get true CPU times for the current thread.
def times
cpu = ThreadBean.current_thread_cpu_time
user = ThreadBean.curent_thread_user_time
thread_mx_bean = java.lang.management.ManagementFactory.thread_mx_bean
cpu = thread_mx_bean.current_thread_cpu_time
user = thread_mx_bean.curent_thread_user_time

cpu = 0 if cpu < 0
user = 0 if user < 0