Skip to content

Commit

Permalink
Merge pull request #330 from u2illc/eq_operator
Browse files Browse the repository at this point in the history
Improve performance of the Equals operator in the RubyComparable class for objects of different types
  • Loading branch information
headius committed Oct 5, 2012
2 parents f94ab12 + 8711597 commit e2c3728
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/org/jruby/RubyComparable.java
Expand Up @@ -116,6 +116,11 @@ private static IRubyObject callCmpMethod(ThreadContext context, IRubyObject recv
try {
IRubyObject result = invokedynamic(context, recv, OP_CMP, other);

// This is only to prevent throwing exceptions by cmperr - it has poor performance
if (result.isNil()) {
return returnValueOnError;
}

return RubyBoolean.newBoolean(runtime, cmpint(context, result, recv, other) == 0);
} catch (RaiseException e) {
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
Expand Down

1 comment on commit e2c3728

@nirvdrum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind converting the tabs to spaces for consistency?

Please sign in to comment.