提交 13acd59c 编写于 作者: M Matt Pharr

InternCache: take optional object creation function in Lookup()

上级 dd0839c4
......@@ -910,7 +910,8 @@ class InternCache {
bufferResource(alloc.resource()),
itemAlloc(&bufferResource) {}
const T *Lookup(const T &item) {
template <typename F>
const T *Lookup(const T &item, F create) {
size_t offset = Hash()(item) % hashTable.size();
int step = 1;
mutex.lock_shared();
......@@ -953,7 +954,7 @@ class InternCache {
// Allocate new hash table entry and add it to the hash table
++nEntries;
T *newPtr = itemAlloc.new_object<T>(item);
T *newPtr = create(itemAlloc, item);
Insert(newPtr, &hashTable);
mutex.unlock();
return newPtr;
......@@ -973,6 +974,12 @@ class InternCache {
}
}
const T *Lookup(const T &item) {
return Lookup(item, [](Allocator alloc, const T &item) {
return alloc.new_object<T>(item);
});
}
size_t size() const { return nEntries; }
size_t capacity() const { return hashTable.size(); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册