• M
    Change Http::Cache::SPECIAL_KEYS from Array to Set · e3123815
    Mindaugas Mozūras 提交于
    Slightly improves performance, for example, a simple benchmark:
    
    ```ruby
    require 'benchmark/ips'
    require 'set'
    
    SPECIAL_KEYS = %w[extras no-cache max-age public must-revalidate]
    SPECIAL_KEYS_SET = Set.new(SPECIAL_KEYS)
    directive = 'must-revalidate'
    
    Benchmark.ips do |x|
      x.report('array') { SPECIAL_KEYS.include?(directive) }
      x.report('set') { SPECIAL_KEYS_SET.include?(directive) }
    end
    ```
    
    Output:
    
    ```
    -------------------------------------
       array     67926 i/100ms
         set     74054 i/100ms
    -------------------------------------
       array  2318423.4 (±2.8%) i/s -   11615346 in   5.014899s
         set  3387981.8 (±4.7%) i/s -   16958366 in   5.019355s
    ```
    e3123815
cache.rb 4.9 KB