Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 201 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 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_LRU_HELPER_H_ | |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_LRU_HELPER_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/hash_tables.h" | |
| 13 #include "gpu/gpu_export.h" | |
| 14 #include "net/disk_cache/hash.h" | |
| 15 | |
| 16 namespace gpu { | |
| 17 namespace gles2 { | |
| 18 | |
| 19 // LRU helper for the program cache, operates in O(1) time. | |
| 20 // This class uses a linked list with a hash map. Both copy their string keys, | |
| 21 // so be mindful that keys you insert will be stored again twice in memory. | |
| 22 class GPU_EXPORT ProgramCacheLruHelper { | |
| 23 public: | |
| 24 ProgramCacheLruHelper() {} | |
| 25 // clears the lru queue | |
| 26 void Clear(); | |
| 27 // returns true if the lru queue is empty | |
| 28 bool IsEmpty(); | |
| 29 // inserts or refreshes a key in the queue | |
| 30 void KeyUsed(const std::string& key); | |
| 31 // Peeks at the next key. Use IsEmpty() first | |
| 32 const std::string& PeekKey(); | |
| 33 // evicts the next key from the queue. | |
| 34 void PopKey(); | |
| 35 | |
| 36 private: | |
| 37 struct FastHash { | |
|
greggman
2012/06/26 23:00:27
again with the FastHash, there's no need to go nut
dmurph
2012/07/04 00:01:29
Done.
| |
| 38 const inline uint32 operator()(const std::string& key) const { | |
| 39 return disk_cache::SuperFastHash(key.data(), | |
| 40 static_cast<int>(key.size())); | |
| 41 } | |
| 42 }; | |
| 43 typedef std::list<std::string> StringList; | |
| 44 typedef base::hash_map<std::string, | |
| 45 StringList::iterator, | |
| 46 FastHash> IteratorMap; | |
| 47 StringList queue; | |
| 48 IteratorMap location_map; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(ProgramCacheLruHelper); | |
| 51 }; | |
| 52 | |
| 53 } // namespace gles2 | |
| 54 } // namespace gpu | |
| 55 | |
| 56 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_LRU_HELPER_H_ | |
| OLD | NEW |