From e3123815898145888fe84f053b14f5cfc33c1684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mindaugas=20Moz=C5=ABras?= Date: Sun, 15 Jun 2014 21:47:37 +0300 Subject: Change Http::Cache::SPECIAL_KEYS from Array to Set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ``` --- actionpack/lib/action_dispatch/http/cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') 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] -- cgit v1.2.3