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

Commits on Nov 17, 2016

  1. Copy the full SHA
    863f420 View commit details
  2. Copy the full SHA
    ed97a60 View commit details
  3. Copy the full SHA
    a425196 View commit details
  4. Copy the full SHA
    cddeb58 View commit details
  5. Copy the full SHA
    1d215bf View commit details
  6. Copy the full SHA
    5a254fc View commit details
  7. Copy the full SHA
    8815c19 View commit details
  8. move single-byte-optimizable check into strLengthFromRubyString

    has been a source of slow-ness for usage such as the `str.index('...')` : 
    
    before:
    ```
    (('foo' * 100) + '012').index('01') [10000000x]      5.120000   0.040000   5.160000 (  5.146903)
    ```
    after:
    ```
    (('foo' * 100) + '012').index('01') [10000000x]     2.280000   0.100000   2.380000 (  2.374061)
    ```
    2.3.1:
    ```
    (('foo' * 100) + '012').index('01') [10000000x]     1.950000   0.000000   1.950000 (  1.955884)
    ```
    kares committed Nov 17, 2016
    Copy the full SHA
    7e7cb5e View commit details
  9. Copy the full SHA
    5deedbd View commit details
  10. Copy the full SHA
    8febff9 View commit details
  11. Copy the full SHA
    dd8e670 View commit details
  12. one adjustStartPos is enough; check() before field (avoids NPE)

    also consintently use runtime local variable instead of getRuntime()
    kares committed Nov 17, 2016
    Copy the full SHA
    2fcd310 View commit details
  13. Copy the full SHA
    a93ed52 View commit details
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -9,13 +9,15 @@ cache:
before_install:
- rm ~/.m2/settings.xml
- export MAVEN_SKIP_RC=true
- mvn -Xmx32M -v | grep 1.7.0; if [ $? = 0 ]; then export MAVEN_OPTS="-XX:MaxPermSize=240M"; else export MAVEN_OPTS="-XX:MaxMetaspaceSize=240M -XX:CompressedClassSpaceSize=240M"; fi
- mvn -Xmx32M -v | grep 1.7.0; if [ $? = 0 ]; then export MAVEN_OPTS="-XX:MaxPermSize=200M"; else export MAVEN_OPTS="-XX:MaxMetaspaceSize=200M -XX:CompressedClassSpaceSize=200M"; fi
- export MAVEN_OPTS="-Xmx512M $MAVEN_OPTS"

before_script:
- unset GEM_PATH GEM_HOME IRBRC JRUBY_OPTS
- export PATH="`pwd`/bin:$PATH"
- echo $HOME
- echo $JAVA_OPTS
- echo $MAVEN_OPTS

jdk:
- openjdk7
26 changes: 26 additions & 0 deletions bench/core/string/bench_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'benchmark'

TIMES = 10_000_000

Benchmark.bmbm do |x|

x.report("'foo'.index('o') [#{TIMES}x]") do
TIMES.times do
'foo'.index('o')
end
end

x.report("'0123456789001234567890'.index('abc') [#{TIMES}x]") do
TIMES.times do
'0123456789001234567890'.index('abc')
end
end

x.report("(('foo' * 100) + '012').index('01') [#{TIMES}x]") do
str = (('foo' * 100) + '012')
TIMES.times do
str.index('01')
end
end

end
90 changes: 41 additions & 49 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -129,14 +129,14 @@ public ClassIndex getNativeClassIndex() {
}

protected final void concurrentModification() {
concurrentModification(getRuntime(), null);
throw concurrentModification(getRuntime(), null);
}

private static void concurrentModification(Ruby runtime, Exception cause) {
private static RuntimeException concurrentModification(Ruby runtime, Exception cause) {
RuntimeException ex = runtime.newConcurrencyError("Detected invalid array contents due to unsynchronized modifications with concurrent users");
// NOTE: probably not useful to be on except for debugging :
// if ( cause != null ) ex.initCause(cause);
throw ex;
return ex;
}

/** rb_ary_s_create
@@ -694,7 +694,7 @@ protected IRubyObject initializeCommon(ThreadContext context, IRubyObject arg0,
fill(values, begin, begin + ilen, arg1);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
throw concurrentModification(runtime, ex);
}
realLength = ilen;
}
@@ -845,8 +845,7 @@ public IRubyObject eltOk(long offset) {
try {
return eltInternal((int)offset);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(getRuntime(), ex);
return null; // not reached
throw concurrentModification(getRuntime(), ex);
}
}

@@ -858,8 +857,7 @@ public IRubyObject eltSetOk(int offset, IRubyObject value) {
try {
return eltInternalSet(offset, value);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(getRuntime(), ex);
return null; // not reached
throw concurrentModification(getRuntime(), ex);
}
}

@@ -976,7 +974,7 @@ private final void splice(long beg, long len, IRubyObject rpl, boolean oneNine)
try {
Helpers.fillNil(values, begin + realLength, begin + ((int) beg), getRuntime());
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
realLength = (int) len;
} else {
@@ -1371,7 +1369,7 @@ public IRubyObject unshift(IRubyObject item) {
if (newLength < ARRAY_DEFAULT_SIZE) newLength = ARRAY_DEFAULT_SIZE;

newLength += valuesLength;
IRubyObject[]vals = new IRubyObject[newLength];
IRubyObject[] vals = new IRubyObject[newLength];
safeArrayCopy(values, begin, vals, 1, valuesLength);
Helpers.fillNil(vals, valuesLength + 1, newLength, getRuntime());
values = vals;
@@ -1858,7 +1856,7 @@ protected RubyString joinStrings(RubyString sep, int max, RubyString result) {
result.append19(eltInternal(i));
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}

return result;
@@ -2070,7 +2068,7 @@ public IRubyObject compact_bang() {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}

p -= begin;
@@ -2121,7 +2119,7 @@ public IRubyObject rb_clear() {
begin = 0;
Helpers.fillNil(values, 0, realLength, getRuntime());
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
}

@@ -2216,7 +2214,7 @@ protected IRubyObject fillCommon(ThreadContext context, int beg, long len, IRuby
try {
fill(values, begin + beg, begin + end, item);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}
}

@@ -2425,7 +2423,7 @@ public IRubyObject reverse_bang() {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
return this;
}
@@ -2457,7 +2455,7 @@ protected RubyArray safeReverse() {
vals[length - i - 1] = myValues[myBegin + i];
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
return new RubyArray(getRuntime(), getMetaClass(), vals);
}
@@ -2652,7 +2650,7 @@ public IRubyObject delete(ThreadContext context, IRubyObject item, Block block)
if (i2 << 1 < valuesLength && valuesLength > ARRAY_DEFAULT_SIZE) realloc(i2 << 1, valuesLength);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}

return value;
@@ -2688,7 +2686,7 @@ public IRubyObject delete_at(int pos) {
System.arraycopy(values, begin + pos + 1, values, begin + pos, len - (pos + 1));
values[begin + len - 1] = getRuntime().getNil();
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(getRuntime(), e);
}
realLength--;

@@ -2760,7 +2758,7 @@ else if (realLength > 0) {
try {
Helpers.fillNil(values, beg + i2, beg + i1, runtime);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
throw concurrentModification(runtime, ex);
}
}
}
@@ -2862,7 +2860,7 @@ private IRubyObject zipCommon(ThreadContext context, IRubyObject[] args, Block b
result[i] = newArrayMayCopy(runtime, tmp);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(runtime, ex);
}
return newArrayMayCopy(runtime, result);
}
@@ -3066,7 +3064,7 @@ protected boolean flatten(ThreadContext context, final int level, final RubyArra
ary = (RubyArray) stack.pop(context);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}
return modified;
}
@@ -3210,7 +3208,7 @@ public IRubyObject op_plus(IRubyObject obj) {
copyInto(z.values, 0);
y.copyInto(z.values, realLength);
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(runtime, e);
}
z.realLength = len;
return z;
@@ -3245,7 +3243,7 @@ public IRubyObject op_times(ThreadContext context, IRubyObject times) {
copyInto(ary2.values, i);
}
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
throw concurrentModification(runtime, e);
}

ary2.infectBy(this);
@@ -3341,7 +3339,7 @@ public IRubyObject uniq(ThreadContext context) {
if (hash.fastDelete(v)) result.values[j++] = v;
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}
result.realLength = j;
return result;
@@ -3362,19 +3360,20 @@ public IRubyObject uniq19(ThreadContext context, Block block) {
*/
@JRubyMethod(name = "-", required = 1)
public IRubyObject op_diff(IRubyObject other) {
Ruby runtime = getRuntime();
RubyHash hash = other.convertToArray().makeHash();
RubyArray ary3 = newArray(getRuntime());
RubyArray ary3 = newArray(runtime);

try {
for (int i = 0; i < realLength; i++) {
IRubyObject value = eltOk(i);
if (hash.fastARef(value) != null) continue;
ary3.append(value);
}
} catch (ArrayIndexOutOfBoundsException aioob) {
concurrentModification();
} catch (ArrayIndexOutOfBoundsException e) {
throw concurrentModification(runtime, e);
}
Helpers.fillNil(ary3.values, ary3.realLength, ary3.values.length, getRuntime());
Helpers.fillNil(ary3.values, ary3.realLength, ary3.values.length, runtime);

return ary3;
}
@@ -3490,7 +3489,7 @@ public int compare(Object o1, Object o2) {
}
});
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}
return this;
}
@@ -4053,7 +4052,7 @@ public IRubyObject shuffle_bang(ThreadContext context, IRubyObject[] args) {
eltSetOk(r, tmp);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}

return this;
@@ -4181,8 +4180,7 @@ public IRubyObject sample(ThreadContext context, IRubyObject[] args) {
return ary;
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
return this; // not reached
throw concurrentModification(context.runtime, ex);
}
}

@@ -4215,10 +4213,10 @@ protected IRubyObject internalRotateBang(ThreadContext context, int cnt) {
}
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}

return context.runtime.getNil();
return context.nil;
}

private static int rotateCount(int cnt, int len) {
@@ -4240,7 +4238,7 @@ protected IRubyObject internalRotate(ThreadContext context, int cnt) {
System.arraycopy(ptr, begin, ptr2, len, cnt);
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(context.runtime, ex);
throw concurrentModification(context.runtime, ex);
}

return rotated;
@@ -4357,7 +4355,7 @@ public static void marshalTo(RubyArray array, MarshalStream output) throws IOExc
output.dumpObject(array.eltInternal(i));
}
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(array.getRuntime(), ex);
throw concurrentModification(array.getRuntime(), ex);
}
}

@@ -4414,9 +4412,8 @@ public RubyString pack(ThreadContext context, IRubyObject obj) {
RubyString iFmt = obj.convertToString();
try {
return Pack.pack(context, context.runtime, this, iFmt);
} catch (ArrayIndexOutOfBoundsException aioob) {
concurrentModification();
return null; // not reached
} catch (ArrayIndexOutOfBoundsException e) {
throw concurrentModification(context.runtime, e);
}
}

@@ -4865,8 +4862,7 @@ private static IRubyObject safeArrayRef(Ruby runtime, IRubyObject[] values, int
try {
return values[i];
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
return null; // not reached
throw concurrentModification(runtime, ex);
}
}

@@ -4878,8 +4874,7 @@ private static IRubyObject safeArraySet(Ruby runtime, IRubyObject[] values, int
try {
return values[i] = value;
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
return null; // not reached
throw concurrentModification(runtime, ex);
}
}

@@ -4893,8 +4888,7 @@ private static IRubyObject safeArrayRefSet(Ruby runtime, IRubyObject[] values, i
values[i] = value;
return tmp;
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification(runtime, e);
return null; // not reached
throw concurrentModification(runtime, e);
}
}

@@ -4908,8 +4902,7 @@ private static IRubyObject safeArrayRefCondSet(Ruby runtime, IRubyObject[] value
if (doSet) values[i] = value;
return tmp;
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
return null; // not reached
throw concurrentModification(runtime, ex);
}
}

@@ -4921,9 +4914,8 @@ private static void safeArrayCopy(Ruby runtime, IRubyObject[] source, int source
try {
System.arraycopy(source, sourceStart, target, targetStart, length);
} catch (ArrayIndexOutOfBoundsException ex) {
concurrentModification(runtime, ex);
throw concurrentModification(runtime, ex);
}
// not reached
}

private static ArraySites sites(ThreadContext context) {
Loading