From 0390c3180d8c198779d98445237eaa035dddd51b Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 12 Dec 2016 12:23:31 -0600 Subject: [PATCH] Speed up Hash lookups with constants Since we are always looking up these hashes with an identical duplicate (not just the same value, the same object) we can take advantage of Hash.compare_by_identity. Suggested by @dgynn in https://github.com/rails/sprockets/issues/383#issuecomment-260101585 --- lib/sprockets/digest_utils.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/sprockets/digest_utils.rb b/lib/sprockets/digest_utils.rb index c6b2e39cd..7053d48a0 100644 --- a/lib/sprockets/digest_utils.rb +++ b/lib/sprockets/digest_utils.rb @@ -80,6 +80,9 @@ def detect_digest_class(bytes) digest << val.to_s } end + + ADD_VALUE_TO_DIGEST.compare_by_identity.rehash + ADD_VALUE_TO_DIGEST.default_proc = ->(_, val) { raise TypeError, "couldn't digest #{ val }" }