Skip to content

Commit

Permalink
Reduce getRuntime/context.runtime calls for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Who828 authored and kares committed Apr 19, 2017
1 parent 9f4a63f commit ceea221
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Expand Up @@ -245,15 +245,15 @@ private IRubyObject initialize(IRubyObject object, IRubyObject method, IRubyObje
}

private IRubyObject initialize20(IRubyObject object, IRubyObject method, IRubyObject[] methodArgs, IRubyObject size) {
final Ruby runtime = getRuntime();
this.object = object;
this.method = method.asJavaString();
this.methodArgs = methodArgs;
this.size = size;
//this.sizeFn = sizeFn;
this.feedValue = getRuntime().getNil();
this.feedValue = runtime.getNil();
setInstanceVariable("@__object__", object);
setInstanceVariable("@__method__", method);
setInstanceVariable("@__args__", RubyArray.newArrayNoCopyLight(getRuntime(), methodArgs));
setInstanceVariable("@__args__", RubyArray.newArrayNoCopyLight(runtime, methodArgs));
return this;
}

Expand All @@ -266,8 +266,7 @@ public IRubyObject dup() {
copy.method = this.method;
copy.methodArgs = this.methodArgs;
copy.size = this.size;
//copy.sizeFn = this.sizeFn;
copy.feedValue = getRuntime().getNil();
copy.feedValue = getRuntime().getNil();
return copy;
}

Expand Down Expand Up @@ -439,8 +438,7 @@ public static IRubyObject with_index19(ThreadContext context, IRubyObject self,
@JRubyMethod
public synchronized IRubyObject next(ThreadContext context) {
ensureNexter(context);

if (!feedValue.isNil()) feedValue = context.runtime.getNil();
if (!feedValue.isNil()) feedValue = context.nil;
return nexter.next();
}

Expand Down Expand Up @@ -473,19 +471,19 @@ public synchronized IRubyObject peekValues(ThreadContext context) {
@JRubyMethod(name = "next_values", compat = RUBY1_9)
public synchronized IRubyObject nextValues(ThreadContext context) {
ensureNexter(context);
if (!feedValue.isNil()) feedValue = context.runtime.getNil();
if (!feedValue.isNil()) feedValue = context.nil;
return RubyArray.newArray(context.runtime, nexter.next());
}

@JRubyMethod(compat = RUBY1_9)
public IRubyObject feed(ThreadContext context, IRubyObject val) {
ensureNexter(context);
if (!feedValue.isNil())
throw getRuntime().newTypeError("feed value already set");

if (!feedValue.isNil()) {
throw context.runtime.newTypeError("feed value already set");
}
feedValue = val;
nexter.setFeedValue(val);
return getRuntime().getNil();
return context.nil;
}

private void ensureNexter(ThreadContext context) {
Expand Down

0 comments on commit ceea221

Please sign in to comment.