summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorcostan <costan@google.com>2018-06-04 12:29:13 -0700
committerVictor Costan <pwnall@chromium.org>2018-06-04 17:24:44 -0700
commit6caf73ad9dae0ee91873bcb39554537b85163770 (patch)
tree6cb793172f082230ea0e23c972e63935cdd8de81 /include
parent6a6bdafcf10f5d4bef1ca52697c38d10c28b1a8b (diff)
downloadleveldb-6caf73ad9dae0ee91873bcb39554537b85163770.tar.gz
Clean up Iterator.
This CL renames the private struct Iterator::Cleanup -> Iterator::CleanupNode, to better reflect that it's a linked list node, and extracts duplicated code from its user in IsEmpty() and Run() methods. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=199175058
Diffstat (limited to 'include')
-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).