Skip to content

Commit

Permalink
Merge pull request #1128 from nanoc/faster-attributes-modified
Browse files Browse the repository at this point in the history
Speed up AttributesModified outdatedness rule
  • Loading branch information
denisdefreyne committed Mar 20, 2017
2 parents 48d8d52 + 52b9b40 commit 9a127e6
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/nanoc/base/services/outdatedness_rules.rb
Expand Up @@ -74,17 +74,29 @@ def apply(obj, outdatedness_checker)
end

class AttributesModified < OutdatednessRule
extend Nanoc::Int::Memoization

include Nanoc::Int::ContractsSupport

def reason
Nanoc::Int::OutdatednessReasons::AttributesModified
end

contract C::Or[Nanoc::Int::ItemRep, Nanoc::Int::Item, Nanoc::Int::Layout], C::Named['Nanoc::Int::OutdatednessChecker'] => C::Bool
def apply(obj, outdatedness_checker)
obj = obj.item if obj.is_a?(Nanoc::Int::ItemRep)

ch_old = outdatedness_checker.checksum_store.attributes_checksum_for(obj)
ch_new = Nanoc::Int::Checksummer.calc_for_attributes_of(obj)
ch_old != ch_new
case obj
when Nanoc::Int::ItemRep
apply(obj.item, outdatedness_checker)
when Nanoc::Int::Item, Nanoc::Int::Layout
ch_old = outdatedness_checker.checksum_store.attributes_checksum_for(obj)
ch_new = Nanoc::Int::Checksummer.calc_for_attributes_of(obj)
res = ch_old != ch_new
res
else
raise ArgumentError
end
end
memoize :apply
end

class RulesModified < OutdatednessRule
Expand Down

0 comments on commit 9a127e6

Please sign in to comment.