<commit_before>require "digest/sha1"
require "rack/utils"
require "tilt"

module Sprockets
  class ConcatenatedAsset
    attr_reader :environment, :content_type, :format_extension
    attr_reader :mtime, :length

    def initialize(environment, pathname)
      @environment      = environment
      @content_type     = pathname.content_type
      @format_extension = pathname.format_extension
      @source_paths     = []
      @source           = []
      @mtime            = Time.at(0)
      @length           = 0
      @digest           = Digest::SHA1.new
      require(pathname)
    end

    def digest
      @digest.hexdigest
    end

    def each(&block)
      @source.each(&block)
    end

    def stale?
      mtime < @source_paths.map { |p| File.mtime(p) }.max
    end

    def to_s
      @source.join
    end

    protected
      attr_reader :source_paths, :source

      def <<(str)
        @length += str.length
        @digest << str
        @source << str
      end

      def requirable?(pathname)
        content_type == pathname.content_type
      end

      def require(pathname)
        if requirable?(pathname)
          unless source_paths.include?(pathname.path)
            source_paths << pathname.path
            self << process(pathname)
          end
        else
          raise ContentTypeMismatch, "#{pathname.path} is " +
            "'#{pathname.format_extension}', not '#{format_extension}'"
        end
      end

      def process(pathname)
        result = process_source(pathname)
        pathname.engine_extensions.reverse_each do |extension|
          result = Tilt[extension].new(pathname.path) { result }.render
        end
        result
      end

      def process_source(pathname)
        source_file = SourceFile.new(pathname)
        processor   = Processor.new(environment, source_file)
        result      = ""

        if source_file.mtime > mtime
          @mtime = source_file.mtime
        end

        processor.required_pathnames.each { |p| require(p) }
        result << source_file.header << "\n" unless source_file.header.empty?
        processor.included_pathnames.each { |p| result << process(p) }
        result << source_file.body

        result
      end
  end
end
<commit_msg>Stale check should short circuit<commit_after>require "digest/sha1"
require "rack/utils"
require "tilt"

module Sprockets
  class ConcatenatedAsset
    attr_reader :environment, :content_type, :format_extension
    attr_reader :mtime, :length

    def initialize(environment, pathname)
      @environment      = environment
      @content_type     = pathname.content_type
      @format_extension = pathname.format_extension
      @source_paths     = []
      @source           = []
      @mtime            = Time.at(0)
      @length           = 0
      @digest           = Digest::SHA1.new
      require(pathname)
    end

    def digest
      @digest.hexdigest
    end

    def each(&block)
      @source.each(&block)
    end

    def stale?
      @source_paths.any? { |p| mtime < File.mtime(p) }
    end

    def to_s
      @source.join
    end

    protected
      attr_reader :source_paths, :source

      def <<(str)
        @length += str.length
        @digest << str
        @source << str
      end

      def requirable?(pathname)
        content_type == pathname.content_type
      end

      def require(pathname)
        if requirable?(pathname)
          unless source_paths.include?(pathname.path)
            source_paths << pathname.path
            self << process(pathname)
          end
        else
          raise ContentTypeMismatch, "#{pathname.path} is " +
            "'#{pathname.format_extension}', not '#{format_extension}'"
        end
      end

      def process(pathname)
        result = process_source(pathname)
        pathname.engine_extensions.reverse_each do |extension|
          result = Tilt[extension].new(pathname.path) { result }.render
        end
        result
      end

      def process_source(pathname)
        source_file = SourceFile.new(pathname)
        processor   = Processor.new(environment, source_file)
        result      = ""

        if source_file.mtime > mtime
          @mtime = source_file.mtime
        end

        processor.required_pathnames.each { |p| require(p) }
        result << source_file.header << "\n" unless source_file.header.empty?
        processor.included_pathnames.each { |p| result << process(p) }
        result << source_file.body

        result
      end
  end
end

{'fraction_non_alphanumeric': 0.09244444444444444, 'fraction_numerical': 0.0017777777777777779, 'mean_word_length': 2.0127175368139225, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 5, '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': '7230711', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1304, 'n_words': 285}