Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/memory/address_hasher.h" | |
| 6 | |
| 7 namespace base { | |
| 8 | |
| 9 size_t AddressHasher::operator()(const void* address) const { | |
|
danakj
2017/02/22 15:28:01
There's no reason to make this an operator() inste
hajimehoshi
2017/02/23 07:23:50
This is just copied from heap_profiler_allocation_
| |
| 10 // The multiplicative hashing scheme from [Knuth 1998]. The value of |a| has | |
| 11 // been chosen carefully based on measurements with real-word data (addresses | |
| 12 // recorded from a Chrome trace run). It is the first prime after 2^17. For | |
|
danakj
2017/02/22 15:28:01
When you say measurements of real-word (should be
hajimehoshi
2017/02/23 07:23:50
ditto.
| |
| 13 // |shift|, 15 yield good results for both 2^18 and 2^19 bucket sizes. | |
| 14 // Microbenchmarks show that this simple scheme outperforms fancy hashes like | |
| 15 // Murmur3 by 20 to 40 percent. | |
| 16 const uintptr_t key = reinterpret_cast<uintptr_t>(address); | |
| 17 const uintptr_t a = 131101; | |
| 18 const uintptr_t shift = 15; | |
| 19 const uintptr_t h = (key * a) >> shift; | |
| 20 return h; | |
| 21 } | |
| 22 | |
| 23 } // namespace base | |
| OLD | NEW |