diff options
| author | ochko <[email protected]> | 2011-12-22 14:26:15 +0900 |
|---|---|---|
| committer | ochko <[email protected]> | 2011-12-22 14:27:36 +0900 |
| commit | c5c5fbc913c1529f9f70a74124f1243863f14416 (patch) | |
| tree | bb1e423a5d32880fb15bdd792b42577b7dca0a20 /lib | |
| parent | 92cca55f4e23c7dedb71035a9711159773a51ed4 (diff) | |
| download | caxlsx-c5c5fbc913c1529f9f70a74124f1243863f14416.tar.gz caxlsx-c5c5fbc913c1529f9f70a74124f1243863f14416.zip | |
Another performance improvement.
method_missing is being called too much.
Instead declared delegate methods for undestructive Array methods
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/util/simple_typed_list.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb index 78d31dc7..21640b3b 100644 --- a/lib/axlsx/util/simple_typed_list.rb +++ b/lib/axlsx/util/simple_typed_list.rb @@ -132,14 +132,18 @@ module Axlsx # :drop_while # :delete_if # :clear - def method_missing(meth, *args, &block) - raise ArgumentError, "#{meth} not supported" if [:replace, :insert, :collect!, :map!, :pop, :delete_if, :reverse!, :shift, :shuffle!, :slice!, :sort!, :uniq!, :unshift, :zip, :flatten!, :fill, :drop, :drop_while, :delete_if, :clear].include? meth.to_sym - if @list.respond_to? meth - @list.send(meth, *args, &block) - else - puts "method:#{meth.inspect}" - super - end + DESTRUCTIVE = ['replace', 'insert', 'collect!', 'map!', 'pop', 'delete_if', + 'reverse!', 'shift', 'shuffle!', 'slice!', 'sort!', 'uniq!', + 'unshift', 'zip', 'flatten!', 'fill', 'drop', 'drop_while', + 'delete_if', 'clear'] + DELEGATES = Array.instance_methods - self.instance_methods - DESTRUCTIVE + + DELEGATES.each do |method| + class_eval %{ + def #{method}(*args, &block) + @list.send(:#{method}, *args, &block) + end + } end # Serializes the list |
