summaryrefslogtreecommitdiff
path: root/lib/psych/visitors/yaml_tree.rb
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-12-22 21:29:00 -0500
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-12-23 18:38:27 +0900
commita2dd8d846da9648aa74b266337429a0ab53d7bd3 (patch)
tree140f870efc83667463f75d11e40c10f6e9e06142 /lib/psych/visitors/yaml_tree.rb
parentd4861854ecde00540c527f36aaacd257e63ed5a4 (diff)
downloadpsych-a2dd8d846da9648aa74b266337429a0ab53d7bd3.zip
[ruby/psych] Optimize cache with `compare_by_identity`
Using `compare_by_identity` gives a 4x performance boost on cache hits. Benchmark in https://github.com/JuanitoFatas/fast-ruby/issues/189
Diffstat (limited to 'lib/psych/visitors/yaml_tree.rb')
-rw-r--r--lib/psych/visitors/yaml_tree.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index 986c57b..ac6777a 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -80,7 +80,7 @@ module Psych
raise(TypeError, "Can't dump #{target.class}") unless method
h[klass] = method
- end
+ end.compare_by_identity
end
def start encoding = Nodes::Stream::UTF8