commit d5274cfcfc01382b00f5f86b26d9eab45b745deb
parent 58b16ca5e8ca2aaaedfac26545f5aaa7864a3598
Author: Tero Tilus <tero@tilus.net>
Date: Fri, 31 Dec 2010 03:42:49 +0200
Improve Singleton performance
Diffstat:
1 file changed, 8 insertions(+), 0 deletions(-)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -607,6 +607,14 @@ module Singleton
## special-case every call to a Singleton object
return nil if @instance.nil?
+ # Speed up further calls by defining a shortcut around method_missing
+ if meth.to_s[-1,1] == '='
+ # Argh! Inconsistency! Setters do not work like all the other methods.
+ class_eval "def self.#{meth}(a); @instance.send :#{meth}, a; end"
+ else
+ class_eval "def self.#{meth}(*a, &b); @instance.send :#{meth}, *a, &b; end"
+ end
+
@instance.send meth, *a, &b
end
def init *args