mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rss/maker/base.rb, lib/rss/maker/itunes.rb: don't use
instance_eval to initialize variables. (speed up) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b9f895e9c8
commit
f6c7804c16
3 changed files with 31 additions and 7 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun Jun 29 17:33:34 2008 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
|
* lib/rss/maker/base.rb, lib/rss/maker/itunes.rb: don't use
|
||||||
|
instance_eval to initialize variables. (speed up)
|
||||||
|
|
||||||
Sun Jun 29 17:31:15 2008 Kouhei Sutou <kou@cozmixng.org>
|
Sun Jun 29 17:31:15 2008 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* lib/rss/rss.rb, test/rss/test_version.rb (RSS::VERSION):
|
* lib/rss/rss.rb, test/rss/test_version.rb (RSS::VERSION):
|
||||||
|
|
|
@ -31,7 +31,9 @@ module RSS
|
||||||
self::OTHER_ELEMENTS << variable_name
|
self::OTHER_ELEMENTS << variable_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_need_initialize_variable(variable_name, init_value="nil")
|
def add_need_initialize_variable(variable_name, init_value=nil,
|
||||||
|
&init_block)
|
||||||
|
init_value ||= init_block
|
||||||
self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
|
self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -45,7 +47,7 @@ module RSS
|
||||||
def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
|
def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
|
||||||
def_delegators("@#{plural}", :each, :size, :empty?, :clear)
|
def_delegators("@#{plural}", :each, :size, :empty?, :clear)
|
||||||
|
|
||||||
add_need_initialize_variable(plural, "[]")
|
add_need_initialize_variable(plural) {[]}
|
||||||
|
|
||||||
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
||||||
def new_#{name}
|
def new_#{name}
|
||||||
|
@ -74,7 +76,9 @@ module RSS
|
||||||
def def_classed_element_without_accessor(name, class_name=nil)
|
def def_classed_element_without_accessor(name, class_name=nil)
|
||||||
class_name ||= Utils.to_class_name(name)
|
class_name ||= Utils.to_class_name(name)
|
||||||
add_other_element(name)
|
add_other_element(name)
|
||||||
add_need_initialize_variable(name, "make_#{name}")
|
add_need_initialize_variable(name) do |object|
|
||||||
|
object.send("make_#{name}")
|
||||||
|
end
|
||||||
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
||||||
private
|
private
|
||||||
def setup_#{name}(feed, current)
|
def setup_#{name}(feed, current)
|
||||||
|
@ -185,7 +189,19 @@ module RSS
|
||||||
private
|
private
|
||||||
def initialize_variables
|
def initialize_variables
|
||||||
self.class.need_initialize_variables.each do |variable_name, init_value|
|
self.class.need_initialize_variables.each do |variable_name, init_value|
|
||||||
instance_eval("@#{variable_name} = #{init_value}", __FILE__, __LINE__)
|
if init_value.nil?
|
||||||
|
value = nil
|
||||||
|
else
|
||||||
|
if init_value.respond_to?(:call)
|
||||||
|
value = init_value.call(self)
|
||||||
|
elsif init_value.is_a?(String)
|
||||||
|
# just for backward compatibility
|
||||||
|
value = instance_eval(init_value, __FILE__, __LINE__)
|
||||||
|
else
|
||||||
|
value = init_value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
instance_variable_set("@#{variable_name}", value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -238,7 +254,8 @@ module RSS
|
||||||
|
|
||||||
def variables
|
def variables
|
||||||
self.class.need_initialize_variables.find_all do |name, init|
|
self.class.need_initialize_variables.find_all do |name, init|
|
||||||
"nil" == init
|
# init == "nil" is just for backward compatibility
|
||||||
|
init.nil? or init == "nil"
|
||||||
end.collect do |name, init|
|
end.collect do |name, init|
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
@ -364,7 +381,9 @@ module RSS
|
||||||
|
|
||||||
%w(xml_stylesheets channel image items textinput).each do |element|
|
%w(xml_stylesheets channel image items textinput).each do |element|
|
||||||
attr_reader element
|
attr_reader element
|
||||||
add_need_initialize_variable(element, "make_#{element}")
|
add_need_initialize_variable(element) do |object|
|
||||||
|
object.send("make_#{element}")
|
||||||
|
end
|
||||||
module_eval(<<-EOC, __FILE__, __LINE__)
|
module_eval(<<-EOC, __FILE__, __LINE__)
|
||||||
private
|
private
|
||||||
def setup_#{element}(feed)
|
def setup_#{element}(feed)
|
||||||
|
|
|
@ -176,7 +176,7 @@ module RSS
|
||||||
|
|
||||||
%w(hour minute second).each do |name|
|
%w(hour minute second).each do |name|
|
||||||
attr_reader(name)
|
attr_reader(name)
|
||||||
add_need_initialize_variable(name, '0')
|
add_need_initialize_variable(name, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def content=(content)
|
def content=(content)
|
||||||
|
|
Loading…
Add table
Reference in a new issue