Skip to content

Commit

Permalink
Only coerce to RubyString once.
Browse files Browse the repository at this point in the history
This was generated via IntelliJ's refactoring tool.  I should have caught that the same call was being made multiple times.  Note for the future.
  • Loading branch information
nirvdrum committed Jan 4, 2015
1 parent e0ea4e8 commit d82038e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -3380,7 +3380,8 @@ public RubyBoolean include_p(ThreadContext context, IRubyObject obj) {
@JRubyMethod(name = "include?")
public RubyBoolean include_p19(ThreadContext context, IRubyObject obj) {
Ruby runtime = context.runtime;
return StringSupport.index(this, this.value, this.strLength(this.checkEncoding(obj.convertToString())), obj.convertToString(), obj.convertToString().value, obj.convertToString().strLength(this.checkEncoding(obj.convertToString())), 0, this.checkEncoding(obj.convertToString())) == -1 ? runtime.getFalse() : runtime.getTrue();
RubyString coerced = obj.convertToString();
return StringSupport.index(this, this.value, this.strLength(this.checkEncoding(coerced)), coerced, coerced.value, coerced.strLength(this.checkEncoding(coerced)), 0, this.checkEncoding(coerced)) == -1 ? runtime.getFalse() : runtime.getTrue();
}

@JRubyMethod
Expand Down

2 comments on commit d82038e

@scrhartley
Copy link

Choose a reason for hiding this comment

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

Does it matter that this.checkEncoding(coerced) is called multiple times?

@nirvdrum
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It probably shouldn't, but I'm planning a refactoring around a lot of this that will obsolete the multiple calls. I had to make the change I did to satisfy a spec that checked invocation count on a mock object.

Please sign in to comment.