Skip to content

Commit

Permalink
Speed up Hash lookups with constants
Browse files Browse the repository at this point in the history
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 #383 (comment)
  • Loading branch information
schneems committed Dec 12, 2016
1 parent b18968a commit 0390c31
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/sprockets/digest_utils.rb
Expand Up @@ -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 }"
}
Expand Down

0 comments on commit 0390c31

Please sign in to comment.