|
|
@ -127,27 +127,38 @@ bool CCacheKeyIterator::next(valtype& key, CKevaData& data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Exit early if no more data is available in either the cache
|
|
|
|
/* Exit early if no more data is available in either the cache
|
|
|
|
nor the base iterator. */ |
|
|
|
nor the base iterator. */ |
|
|
|
if (!baseHasMore && cacheIter == cache.entries.end()) |
|
|
|
|
|
|
|
|
|
|
|
bool endOfCacheNamespace = false; |
|
|
|
|
|
|
|
if (cacheIter != cache.entries.end()) { |
|
|
|
|
|
|
|
valtype curNameSpace = std::get<0>(cacheIter->first); |
|
|
|
|
|
|
|
if (curNameSpace != nameSpace) { |
|
|
|
|
|
|
|
endOfCacheNamespace = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bool noMoreCache = (cacheIter == cache.entries.end()) || endOfCacheNamespace; |
|
|
|
|
|
|
|
if (!baseHasMore && noMoreCache) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Determine which source to use for the next. */ |
|
|
|
/* Determine which source to use for the next. */ |
|
|
|
bool useBase; |
|
|
|
bool useBase = false; |
|
|
|
if (!baseHasMore) |
|
|
|
if (!baseHasMore) { |
|
|
|
useBase = false; |
|
|
|
useBase = false; |
|
|
|
else if (cacheIter == cache.entries.end()) |
|
|
|
} else if (cacheIter == cache.entries.end()) { |
|
|
|
useBase = true; |
|
|
|
useBase = true; |
|
|
|
else { |
|
|
|
} else { |
|
|
|
|
|
|
|
if (baseKey == std::get<1>(cacheIter->first)) { |
|
|
|
/* A special case is when both iterators are equal. In this case,
|
|
|
|
/* A special case is when both iterators are equal. In this case,
|
|
|
|
we want to use the cached version. We also have to advance |
|
|
|
we want to use the cached version. We also have to advance |
|
|
|
the base iterator. */ |
|
|
|
the base iterator. */ |
|
|
|
if (baseKey == std::get<1>(cacheIter->first)) |
|
|
|
|
|
|
|
advanceBaseIterator (); |
|
|
|
advanceBaseIterator (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Due to advancing the base iterator above, it may happen that
|
|
|
|
/* Due to advancing the base iterator above, it may happen that
|
|
|
|
no more base entries are present. Handle this gracefully. */ |
|
|
|
no more base entries are present. Handle this gracefully. */ |
|
|
|
if (!baseHasMore) |
|
|
|
if (!baseHasMore) { |
|
|
|
useBase = false; |
|
|
|
useBase = false; |
|
|
|
else { |
|
|
|
} else { |
|
|
|
assert(baseKey != std::get<1>(cacheIter->first)); |
|
|
|
assert(baseKey != std::get<1>(cacheIter->first)); |
|
|
|
|
|
|
|
|
|
|
|
CKevaCache::KeyComparator cmp; |
|
|
|
CKevaCache::KeyComparator cmp; |
|
|
|