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

Commits on Apr 29, 2016

  1. Verified

    This commit was signed with the committer’s verified signature.
    makenowjust Hiroya Fujinami
    Copy the full SHA
    7af3491 View commit details
  2. Copy the full SHA
    8dd91cd View commit details
Showing with 86 additions and 2 deletions.
  1. +1 −1 core/pom.rb
  2. +1 −1 core/pom.xml
  3. +84 −0 core/src/main/java/org/jruby/RubyArray.java
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
'tzdata.version' => '2013d',
'tzdata.scope' => 'provided',

'unsafe.version' => '8.92',
'unsafe.version' => '8.92.1-SNAPSHOT',
'unsafe.jar' => '${settings.localRepository}/com/headius/unsafe-mock/${unsafe.version}/unsafe-mock-${unsafe.version}.jar',

'maven.build.timestamp.format' => 'yyyy-MM-dd',
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ DO NOT MODIFIY - GENERATED CODE
<jruby.launch.memory>1024M</jruby.launch.memory>
<jruby.compile.memory>2G</jruby.compile.memory>
<version.ruby.major>2.3</version.ruby.major>
<unsafe.version>8.92</unsafe.version>
<unsafe.version>8.92.1-SNAPSHOT</unsafe.version>
<release.dir>release</release.dir>
<lib.dir>lib</lib.dir>
<rails.dir>${test.dir}/rails</rails.dir>
84 changes: 84 additions & 0 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -4198,6 +4198,90 @@ final IRubyObject dig(ThreadContext context, IRubyObject[] args, int idx) {
return idx == args.length ? val : RubyObject.dig(context, val, args, idx);
}

@JRubyMethod(name = "max")
public IRubyObject max(ThreadContext context, Block block) {
// TODO: check for overwritten <=> on Fixnum and String
// struct cmp_opt_data cmp_opt = { 0, 0 };
IRubyObject result = UNDEF, v;
int i;

if (block.isGiven()) {
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || RubyComparable.cmpint(context, block.yieldSpecific(context, v, result), v, result) > 0) {
result = v;
}
}
} else {
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || optimizedCmp(context, v, result/*, cmp_opt*/) > 0) {
result = v;
}
}
}
if (result == UNDEF) return context.nil;
return result;
}

@JRubyMethod(name = "max")
public IRubyObject max(ThreadContext context, IRubyObject num, Block block) {
if (!num.isNil()) {
return RubyEnumerable.max(context, this, num, block);
}

return max(context, block);
}

@JRubyMethod(name = "min")
public IRubyObject min(ThreadContext context, Block block) {
// TODO: check for overwritten <=> on Fixnum and String
// struct cmp_opt_data cmp_opt = { 0, 0 };
IRubyObject result = UNDEF, v;
int i;

if (block.isGiven()) {
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || RubyComparable.cmpint(context, block.yieldSpecific(context, v, result), v, result) < 0) {
result = v;
}
}
}
else {
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || optimizedCmp(context, v, result/*, cmp_opt*/) < 0) {
result = v;
}
}
}
if (result == UNDEF) return context.nil;
return result;
}

@JRubyMethod(name = "min")
public IRubyObject min(ThreadContext context, IRubyObject num, Block block) {
if (!num.isNil()) {
return RubyEnumerable.min(context, this, num, block);
}

return min(context, block);
}

private static final int optimizedCmp(ThreadContext context, IRubyObject a, IRubyObject b/*, IRubyObject data*/) {
// TODO: check for overwritten <=> on Fixnum and String
if (a instanceof RubyFixnum && b instanceof RubyFixnum /*&& CMP_OPTIMIZABLE(data, Fixnum)*/) {
long aLong = ((RubyFixnum)a).getLongValue();
long bLong = ((RubyFixnum)b).getLongValue();
return aLong > bLong ? 1 : aLong < bLong ? -1 : 0;
} else if (a instanceof RubyString && b instanceof RubyString /*&& CMP_OPTIMIZABLE(data, String)*/) {
return ((RubyString)a).op_cmp((RubyString)b);
}

return RubyComparable.cmpint(context, invokedynamic(context, a, OP_CMP, b), a, b);
}

@Override
public Class getJavaClass() {
return List.class;