<commit_before>module PNG
  class Filters
    #TODO: feature envy, this behavior belongs to a row. 
    def self.fetch_pixel(idx, row)
      return 0 if row.empty?
      return 0 if idx < 0
      return row[idx] || 0
    end

    def self.[]( filter_num )
      FILTERS[ filter_num ]
    end

    NONE = lambda {|value, index, row, last_row| value}
    LEFT = lambda {|value, index, row, last_row|
             (value + fetch_pixel(index - 3, row)) % 256
           }
    UP  = lambda {|value, index, row, last_row|
             (value + fetch_pixel(index, last_row)) % 256
           }
    AVG  = lambda {|value, index, row, last_row| 
             (value + ( (fetch_pixel(index - 3, row) + fetch_pixel(index, last_row)) / 2 ).floor) % 256
           }
    PAETH  = lambda {|value, index, row, last_row| 
               a = fetch_pixel(index - 3, row)
               b = fetch_pixel(index, last_row)
               c = fetch_pixel(index - 3, last_row)
               p = a + b - c
               pa = (p - a).abs
               pb = (p - b).abs
               pc = (p - c).abs

               pr = c
               if ( pa <= pb and pa <= pc) 
                 pr = a
               elsif (pb <= pc)
                 pr = b
               end

               (value + pr) % 256
             }

    FILTERS = {0 => NONE,
               1 => LEFT, 
               2 => UP,
               3 => AVG,
               4 => PAETH}

  end
end
<commit_msg>removing un-needed check from innerest of inner loop<commit_after>module PNG
  class Filters
    #TODO: feature envy, this behavior belongs to a row. 
    def self.fetch_pixel(idx, row)
      return 0 if idx < 0
      return row[idx] || 0
    end

    def self.[]( filter_num )
      FILTERS[ filter_num ]
    end

    NONE = lambda {|value, index, row, last_row| value}
    LEFT = lambda {|value, index, row, last_row|
             (value + fetch_pixel(index - 3, row)) % 256
           }
    UP  = lambda {|value, index, row, last_row|
             (value + fetch_pixel(index, last_row)) % 256
           }
    AVG  = lambda {|value, index, row, last_row| 
             (value + ( (fetch_pixel(index - 3, row) + fetch_pixel(index, last_row)) / 2 ).floor) % 256
           }
    PAETH  = lambda {|value, index, row, last_row| 
               a = fetch_pixel(index - 3, row)
               b = fetch_pixel(index, last_row)
               c = fetch_pixel(index - 3, last_row)
               p = a + b - c
               pa = (p - a).abs
               pb = (p - b).abs
               pc = (p - c).abs

               pr = c
               if ( pa <= pb and pa <= pc) 
                 pr = a
               elsif (pb <= pc)
                 pr = b
               end

               (value + pr) % 256
             }

    FILTERS = {0 => NONE,
               1 => LEFT, 
               2 => UP,
               3 => AVG,
               4 => PAETH}

  end
end

{'fraction_non_alphanumeric': 0.11260330578512397, 'fraction_numerical': 0.01756198347107438, 'mean_word_length': 1.220948012232416, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '774264', 'n_tokens_mistral': 979, 'n_tokens_neox': 889, 'n_words': 283}