<commit_before>require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/hash/slice'

module ActionDispatch
  module Http
    module URL
      IP_HOST_REGEXP  = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
      HOST_REGEXP     = /(^.*:\/\/)?([^:]+)(?::(\d+$))?/
      PROTOCOL_REGEXP = /^([^:]+)(:)?(\/\/)?$/

      mattr_accessor :tld_length
      self.tld_length = 1

      class << self
        def extract_domain(host, tld_length = @@tld_length)
          host.split('.').last(1 + tld_length).join('.') if named_host?(host)
        end

        def extract_subdomains(host, tld_length = @@tld_length)
          if named_host?(host)
            parts = host.split('.')
            parts[0..-(tld_length + 2)]
          else
            []
          end
        end

        def extract_subdomain(host, tld_length = @@tld_length)
          extract_subdomains(host, tld_length).join('.')
        end

        def url_for(options)
          unless options[:host] || options[:only_path]
            raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true'
          end

          path  = options[:script_name].to_s.chomp("/")
          path << options[:path].to_s

          if options[:only_path]
            result = ''
          else
            result = build_host_url(options)
          end

          if options[:trailing_slash]
            if path.include?('?')
              result << path.sub(/\?/, '/\&')
            else
              result << path.sub(/[^\/]\z|\A\z/, '\&/')
            end
          else
            result << path
          end

          if options.key? :params<commit_msg>mutate the path string to avoid object allocations<commit_after>require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/hash/slice'

module ActionDispatch
  module Http
    module URL
      IP_HOST_REGEXP  = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
      HOST_REGEXP     = /(^.*:\/\/)?([^:]+)(?::(\d+$))?/
      PROTOCOL_REGEXP = /^([^:]+)(:)?(\/\/)?$/

      mattr_accessor :tld_length
      self.tld_length = 1

      class << self
        def extract_domain(host, tld_length = @@tld_length)
          host.split('.').last(1 + tld_length).join('.') if named_host?(host)
        end

        def extract_subdomains(host, tld_length = @@tld_length)
          if named_host?(host)
            parts = host.split('.')
            parts[0..-(tld_length + 2)]
          else
            []
          end
        end

        def extract_subdomain(host, tld_length = @@tld_length)
          extract_subdomains(host, tld_length).join('.')
        end

        def url_for(options)
          unless options[:host] || options[:only_path]
            raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true'
          end

          path  = options[:script_name].to_s.chomp("/")
          path << options[:path].to_s

          if options[:only_path]
            result = ''
          else
            result = build_host_url(options)
          end

          if options[:trailing_slash]
            if path.include?('?')
              path.sub!(/\?/, '/\&')
            else
              path.sub!(/[^\/]\z|\A\z/, '\&/')
            end
          end

          result << path

          if options.key? :params
{'fraction_non_alphanumeric': 0.15268505079825834, 'fraction_numerical': 0.006966618287373005, 'mean_word_length': 1.8199672667757774, 'pattern_counts': {'":': 0, '<': 19, '<?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': '5514623', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1081, 'n_words': 209}