summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-02 21:24:54 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-02 21:24:54 +0000
commitad9aa5368fb6a34294fb9cd4e48aed3bae244dbf (patch)
treed4f4fe12c012e889a9dd4c5e98335e6adcb0819e
parent8114da9e6be525e0d4bd5107f8f2aa97c5560bc6 (diff)
* ext/psych/lib/psych/visitors/visitor.rb (accept): switch to
a dispatch cache rather than case / when statement. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/psych/lib/psych/visitors/visitor.rb21
2 files changed, 16 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 55dbb0b81d..f3848f2c8a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Nov 2 22:47:08 2010 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * ext/psych/lib/psych/visitors/visitor.rb (accept): switch to
+ a dispatch cache rather than case / when statement.
+
Tue Nov 2 21:46:52 2010 Kouhei Sutou <kou@cozmixng.org>
* NEWS: fix a typo.
diff --git a/ext/psych/lib/psych/visitors/visitor.rb b/ext/psych/lib/psych/visitors/visitor.rb
index 3471c43dfa..0e33128f01 100644
--- a/ext/psych/lib/psych/visitors/visitor.rb
+++ b/ext/psych/lib/psych/visitors/visitor.rb
@@ -11,16 +11,17 @@ module Psych
end
def accept target
- case target
- when Psych::Nodes::Scalar then visit_Psych_Nodes_Scalar target
- when Psych::Nodes::Mapping then visit_Psych_Nodes_Mapping target
- when Psych::Nodes::Sequence then visit_Psych_Nodes_Sequence target
- when Psych::Nodes::Alias then visit_Psych_Nodes_Alias target
- when Psych::Nodes::Document then visit_Psych_Nodes_Document target
- when Psych::Nodes::Stream then visit_Psych_Nodes_Stream target
- else
- raise "Can't handle #{target}"
- end
+ visit target
+ end
+
+ private
+
+ DISPATCH = Hash.new do |hash, klass|
+ hash[klass] = "visit_#{klass.name.gsub('::', '_')}"
+ end
+
+ def visit target
+ send DISPATCH[target.class], target
end
end
end