aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorMindaugas Mozūras <mindaugas.mozuras@gmail.com>2014-06-15 21:47:37 +0300
committerMindaugas Mozūras <mindaugas.mozuras@gmail.com>2014-06-15 22:26:15 +0300
commite3123815898145888fe84f053b14f5cfc33c1684 (patch)
treed7dd4a2bd3582d86bb6f80ff86255c107889cbee /actionpack
parent3268a04e991994e37515873339e120deba1ce144 (diff)
downloadrails-e3123815898145888fe84f053b14f5cfc33c1684.tar.gz
rails-e3123815898145888fe84f053b14f5cfc33c1684.tar.bz2
rails-e3123815898145888fe84f053b14f5cfc33c1684.zip
Change Http::Cache::SPECIAL_KEYS from Array to Set
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 ```
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/http/cache.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb
index f9b278349e..63a3cbc90b 100644
--- a/actionpack/lib/action_dispatch/http/cache.rb
+++ b/actionpack/lib/action_dispatch/http/cache.rb
@@ -92,7 +92,7 @@ module ActionDispatch
LAST_MODIFIED = "Last-Modified".freeze
ETAG = "ETag".freeze
CACHE_CONTROL = "Cache-Control".freeze
- SPECIAL_KEYS = %w[extras no-cache max-age public must-revalidate]
+ SPECIAL_KEYS = Set.new(%w[extras no-cache max-age public must-revalidate])
def cache_control_segments
if cache_control = self[CACHE_CONTROL]