summaryrefslogtreecommitdiff
path: root/include/leveldb/iterator.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/leveldb/iterator.h')
-rw-r--r--include/leveldb/iterator.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/include/leveldb/iterator.h b/include/leveldb/iterator.h
index 436508a..6c1d91b 100644
--- a/include/leveldb/iterator.h
+++ b/include/leveldb/iterator.h
@@ -77,17 +77,25 @@ class LEVELDB_EXPORT Iterator {
//
// Note that unlike all of the preceding methods, this method is
// not abstract and therefore clients should not override it.
- typedef void (*CleanupFunction)(void* arg1, void* arg2);
+ using CleanupFunction = void (*)(void* arg1, void* arg2);
void RegisterCleanup(CleanupFunction function, void* arg1, void* arg2);
private:
- struct Cleanup {
+ // Cleanup functions are stored in a single-linked list.
+ // The list's head node is inlined in the iterator.
+ struct CleanupNode {
+ // The head node is used if the function pointer is not null.
CleanupFunction function;
void* arg1;
void* arg2;
- Cleanup* next;
+ CleanupNode* next;
+
+ // True if the node is not used. Only head nodes might be unused.
+ bool IsEmpty() const { return function == nullptr; }
+ // Invokes the cleanup function.
+ void Run() { assert(function != nullptr); (*function)(arg1, arg2); }
};
- Cleanup cleanup_;
+ CleanupNode cleanup_head_;
};
// Return an empty iterator (yields nothing).