lib/flay.rb in flay-2.11.0 vs lib/flay.rb in flay-2.12.0

- old
+ new

@@ -15,11 +15,11 @@ alias :binread :read unless RUBY19 end end class Flay - VERSION = "2.11.0" # :nodoc: + VERSION = "2.12.0" # :nodoc: class Item < Struct.new(:structural_hash, :name, :bonus, :mass, :locations) alias identical? bonus end @@ -279,17 +279,29 @@ warn "TIMEOUT parsing #{file}. Skipping." end end ## + # Before processing, filter any sexp's that match against filters + # specified in +option[:filters]+. This changes the sexp itself. + + def filter_sexp exp + exp.delete_if { |sexp| + if Sexp === sexp then + del = option[:filters].any? { |pattern| pattern.satisfy? sexp } + del or (filter_sexp(sexp); false) + end + } + end + + ## # Process a sexp +pt+. def process_sexp pt - pt.deep_each do |node| + filter_sexp(pt).deep_each do |node| next :skip if node.none? { |sub| Sexp === sub } next :skip if node.mass < self.mass_threshold - next :skip if option[:filters].any? { |pattern| pattern.satisfy? node } self.hashes[node.structural_hash] << node process_fuzzy node, option[:fuzzy] if option[:fuzzy] end @@ -329,26 +341,10 @@ end end end ## - # Given an array of sexp patterns (see sexp_processor), delete any - # buckets whose members match any of the patterns. - - def filter *patterns - return if patterns.empty? - - self.hashes.delete_if { |_, sexps| - sexps.any? { |sexp| - patterns.any? { |pattern| - pattern =~ sexp - } - } - } - end - - ## # Prunes nodes that aren't relevant to analysis or are already # covered by another node. Also deletes nodes based on the # +:filters+ option. def prune @@ -359,11 +355,9 @@ if option[:liberal] then prune_liberally else prune_conservatively end - - self.filter(*option[:filters]) end ## # Conservative prune. Remove any bucket that is known to contain a # subnode element of a node in another bucket.