Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Optimization to bind define_method with unbound method directly.
Before this change, we would rebind the method passed to Module#
define_method every invocation. However, since the only
requirement for define_method against a method or unbound method
is that the rebind would succeed (by having the method in the
same hierarchy), rebinding for every object is unnecessary. This
optimization removes that rebinding and just transplant the method
from the source to the original DynamicMethod. Invocations of the
name bound by define_method then perform exactly as the original.

This could be more useful if the UnboundMethod could come from any
module, since modules can in theory live in any hierarchy.
Libraries of utility methods could be assembled via define_method
into other classes. I may explore that as a feature to present to
the other implementers.
  • Loading branch information
headius committed Mar 6, 2013
1 parent f0e3aa3 commit b874552
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/jruby/RubyModule.java
Expand Up @@ -1508,7 +1508,7 @@ public IRubyObject define_method(ThreadContext context, IRubyObject arg0, IRubyO
RubyMethod method = (RubyMethod)arg1;
body = method;

newMethod = new MethodMethod(this, method.unbind(), visibility);
newMethod = method.unbind().getMethod();
} else {
throw runtime.newTypeError("wrong argument type " + arg1.getType().getName() + " (expected Proc/Method)");
}
Expand Down

0 comments on commit b874552

Please sign in to comment.