Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/compiler/node-cache.h

Issue 624153003: Add C++11 compatible base::hash function object. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: NodeCache Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/base/functional.cc ('k') | src/compiler/node-cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_COMPILER_NODE_CACHE_H_ 5 #ifndef V8_COMPILER_NODE_CACHE_H_
6 #define V8_COMPILER_NODE_CACHE_H_ 6 #define V8_COMPILER_NODE_CACHE_H_
7 7
8 #include "src/v8.h" 8 #include "src/base/functional.h"
9 9 #include "src/base/macros.h"
10 #include "src/compiler/node.h"
11 10
12 namespace v8 { 11 namespace v8 {
13 namespace internal { 12 namespace internal {
13
14 // Forward declarations.
15 class Zone;
16
17
14 namespace compiler { 18 namespace compiler {
15 19
20 // Forward declarations.
21 class Node;
22
23
16 // A cache for nodes based on a key. Useful for implementing canonicalization of 24 // A cache for nodes based on a key. Useful for implementing canonicalization of
17 // nodes such as constants, parameters, etc. 25 // nodes such as constants, parameters, etc.
18 template <typename Key> 26 template <typename Key, typename Hash = base::hash<Key>,
19 class NodeCache { 27 typename Pred = std::equal_to<Key> >
28 class NodeCache FINAL {
20 public: 29 public:
21 explicit NodeCache(int max = 256) : entries_(NULL), size_(0), max_(max) {} 30 explicit NodeCache(size_t max = 256)
31 : entries_(nullptr), size_(0), max_(max) {}
22 32
23 // Search for node associated with {key} and return a pointer to a memory 33 // Search for node associated with {key} and return a pointer to a memory
24 // location in this cache that stores an entry for the key. If the location 34 // location in this cache that stores an entry for the key. If the location
25 // returned by this method contains a non-NULL node, the caller can use that 35 // returned by this method contains a non-NULL node, the caller can use that
26 // node. Otherwise it is the responsibility of the caller to fill the entry 36 // node. Otherwise it is the responsibility of the caller to fill the entry
27 // with a new node. 37 // with a new node.
28 // Note that a previous cache entry may be overwritten if the cache becomes 38 // Note that a previous cache entry may be overwritten if the cache becomes
29 // too full or encounters too many hash collisions. 39 // too full or encounters too many hash collisions.
30 Node** Find(Zone* zone, Key key); 40 Node** Find(Zone* zone, Key key);
31 41
32 private: 42 private:
33 struct Entry { 43 enum { kInitialSize = 16u, kLinearProbe = 5u };
34 Key key_; 44
35 Node* value_; 45 struct Entry;
36 };
37 46
38 Entry* entries_; // lazily-allocated hash entries. 47 Entry* entries_; // lazily-allocated hash entries.
39 int32_t size_; 48 size_t size_;
40 int32_t max_; 49 size_t max_;
50 Hash hash_;
51 Pred pred_;
41 52
42 bool Resize(Zone* zone); 53 bool Resize(Zone* zone);
43 }; 54 };
44 55
45 // Various default cache types. 56 // Various default cache types.
46 typedef NodeCache<int64_t> Int64NodeCache; 57 typedef NodeCache<int64_t> Int64NodeCache;
47 typedef NodeCache<int32_t> Int32NodeCache; 58 typedef NodeCache<int32_t> Int32NodeCache;
48 typedef NodeCache<void*> PtrNodeCache; 59 typedef NodeCache<void*> PtrNodeCache;
49 } 60
50 } 61 } // namespace compiler
51 } // namespace v8::internal::compiler 62 } // namespace internal
63 } // namespace v8
52 64
53 #endif // V8_COMPILER_NODE_CACHE_H_ 65 #endif // V8_COMPILER_NODE_CACHE_H_
OLDNEW
« no previous file with comments | « src/base/functional.cc ('k') | src/compiler/node-cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698