<commit_before>module Atomy::Patterns
  class List < Pattern
    attr_reader :patterns

    def initialize(ps)
      @patterns = ps
    end

    def construct(g)
      get(g)
      @patterns.each do |p|
        p.construct(g)
      end
      g.make_array @patterns.size
      g.send :new, 1
    end

    def ==(b)
      b.kind_of?(List) and \
      @patterns == b.patterns
    end

    def target(g)
      g.push_const :Array
    end

    def matches?(g)
      matched = g.new_label
      mismatch = g.new_label

      g.dup
      g.send :size, 0
      g.push @patterns.size
      g.send :==, 1
      g.gif mismatch

      @patterns.each do |p|
        g.shift_array
        p.matches?(g)
        g.gif mismatch
      end
      g.pop

      g.push_true
      g.goto matched

      mismatch.set!
      g.pop
      g.push_false
<commit_msg>List pattern now checks kind_of before checking size<commit_after>module Atomy::Patterns
  class List < Pattern
    attr_reader :patterns

    def initialize(ps)
      @patterns = ps
    end

    def construct(g)
      get(g)
      @patterns.each do |p|
        p.construct(g)
      end
      g.make_array @patterns.size
      g.send :new, 1
    end

    def ==(b)
      b.kind_of?(List) and \
      @patterns == b.patterns
    end

    def target(g)
      g.push_const :Array
    end

    def matches?(g)
      matched = g.new_label
      mismatch = g.new_label

      g.dup
      g.push_cpath_top
      g.find_const :Array
      g.swap
      g.kind_of
      g.gif mismatch

      g.dup
      g.send :size, 0
      g.push @patterns.size
      g.send :==, 1
      g.gif mismatch

      @patterns.each do |p|
        g.shift_array
        p.matches?(g)
        g.gif mismatch
      end
      g.pop

      g.push_true
      g.goto matched

      mismatch.set!
      g.pop
      g.push_false

{'fraction_non_alphanumeric': 0.09359605911330049, 'fraction_numerical': 0.003284072249589491, 'mean_word_length': 1.5424200278164117, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '470650', 'n_tokens_mistral': 668, 'n_tokens_neox': 647, 'n_words': 153}