Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Hamster::Set in checksummer for speed #887

Merged
merged 1 commit into from Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/nanoc/base/checksummer.rb
@@ -1,3 +1,5 @@
require 'hamster'

module Nanoc::Int
# Creates checksums for given objects.
#
Expand Down Expand Up @@ -46,14 +48,14 @@ def calc(obj, digest_class = CompactDigest)

private

def update(obj, digest, visited = Set.new)
def update(obj, digest, visited = Hamster::Set.new)
digest.update(obj.class.to_s)

if visited.include?(obj)
digest.update('<recur>')
else
digest.update('<')
behavior_for(obj).update(obj, digest) { |o| update(o, digest, visited + [obj]) }
behavior_for(obj).update(obj, digest) { |o| update(o, digest, visited.add(obj)) }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could’ve left it that way, but #add is a nicer API, and it’s likely faster as well.

digest.update('>')
end
end
Expand Down
1 change: 1 addition & 0 deletions nanoc.gemspec
Expand Up @@ -25,6 +25,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.1.0'

s.add_runtime_dependency('cri', '~> 2.3')
s.add_runtime_dependency('hamster', '~> 3.0')

s.add_development_dependency('bundler', '>= 1.7.10', '< 2.0')
end