提交 13c4cc3b 编写于 作者: A Aaron Patterson

remove object `hash` cache

I don't think caching this method makes any difference on Ruby 2.0:

```
require 'benchmark/ips'

class Foo
  alias :object_hash :hash
  attr_reader :hash
  def initialize
    @hash = object_hash
  end
end

class Bar
end

hash = {}
foo = Foo.new
bar = Bar.new
Benchmark.ips do |x|
  x.report("foo") { hash[foo] }
  x.report("bar") { hash[bar] }

  x.report("foo.hash") { foo.hash }
  x.report("bar.hash") { bar.hash }
end

__END__
[aaron@TC ruby (trunk)]$ ruby test.rb
Warming up --------------------------------------
                 foo   118.361k i/100ms
                 bar   118.637k i/100ms
Calculating -------------------------------------
                 foo      7.944M (± 3.1%) i/s -     39.769M
                 bar      7.931M (± 3.4%) i/s -     39.625M
[aaron@TC ruby (trunk)]$ ruby test.rb
Warming up --------------------------------------
                 foo   122.180k i/100ms
                 bar   120.492k i/100ms
            foo.hash   123.397k i/100ms
            bar.hash   119.312k i/100ms
Calculating -------------------------------------
                 foo      8.002M (± 4.2%) i/s -     39.953M
                 bar      8.037M (± 4.5%) i/s -     40.124M
            foo.hash      8.819M (± 3.9%) i/s -     44.053M
            bar.hash      7.856M (± 4.1%) i/s -     39.254M
```
上级 d81e6bbb
......@@ -55,9 +55,7 @@ module Accessors #:nodoc:
class DetailsKey #:nodoc:
alias :eql? :equal?
alias :object_hash :hash
attr_reader :hash
@details_keys = Concurrent::Map.new
def self.get(details)
......@@ -71,10 +69,6 @@ def self.get(details)
def self.clear
@details_keys.clear
end
def initialize
@hash = object_hash
end
end
# Add caching behavior on top of Details.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册