提交 e3123815 编写于 作者: M Mindaugas Mozūras

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
```
上级 3268a04e
......@@ -92,7 +92,7 @@ def etag=(etag)
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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册