/bitcoin/src/leveldb/table/iterator.cc
Line | Count | Source |
1 | | // Copyright (c) 2011 The LevelDB 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. See the AUTHORS file for names of contributors. |
4 | | |
5 | | #include "leveldb/iterator.h" |
6 | | |
7 | | namespace leveldb { |
8 | | |
9 | 71.9k | Iterator::Iterator() { |
10 | 71.9k | cleanup_head_.function = nullptr; |
11 | 71.9k | cleanup_head_.next = nullptr; |
12 | 71.9k | } |
13 | | |
14 | 71.9k | Iterator::~Iterator() { |
15 | 71.9k | if (!cleanup_head_.IsEmpty()) { Branch (15:7): [True: 35.9k, False: 36.0k]
|
16 | 35.9k | cleanup_head_.Run(); |
17 | 35.9k | for (CleanupNode* node = cleanup_head_.next; node != nullptr;) { Branch (17:50): [True: 0, False: 35.9k]
|
18 | 0 | node->Run(); |
19 | 0 | CleanupNode* next_node = node->next; |
20 | 0 | delete node; |
21 | 0 | node = next_node; |
22 | 0 | } |
23 | 35.9k | } |
24 | 71.9k | } |
25 | | |
26 | 35.9k | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { |
27 | 35.9k | assert(func != nullptr); Branch (27:3): [True: 35.9k, False: 0]
|
28 | 35.9k | CleanupNode* node; |
29 | 35.9k | if (cleanup_head_.IsEmpty()) { Branch (29:7): [True: 35.9k, False: 0]
|
30 | 35.9k | node = &cleanup_head_; |
31 | 35.9k | } else { |
32 | 0 | node = new CleanupNode(); |
33 | 0 | node->next = cleanup_head_.next; |
34 | 0 | cleanup_head_.next = node; |
35 | 0 | } |
36 | 35.9k | node->function = func; |
37 | 35.9k | node->arg1 = arg1; |
38 | 35.9k | node->arg2 = arg2; |
39 | 35.9k | } |
40 | | |
41 | | namespace { |
42 | | |
43 | | class EmptyIterator : public Iterator { |
44 | | public: |
45 | 0 | EmptyIterator(const Status& s) : status_(s) {} |
46 | 0 | ~EmptyIterator() override = default; |
47 | | |
48 | 0 | bool Valid() const override { return false; } |
49 | 0 | void Seek(const Slice& target) override {} |
50 | 0 | void SeekToFirst() override {} |
51 | 0 | void SeekToLast() override {} |
52 | 0 | void Next() override { assert(false); } Branch (52:26): [Folded - Ignored]
|
53 | 0 | void Prev() override { assert(false); } Branch (53:26): [Folded - Ignored]
|
54 | 0 | Slice key() const override { |
55 | 0 | assert(false); Branch (55:5): [Folded - Ignored]
|
56 | 0 | return Slice(); |
57 | 0 | } |
58 | 0 | Slice value() const override { |
59 | 0 | assert(false); Branch (59:5): [Folded - Ignored]
|
60 | 0 | return Slice(); |
61 | 0 | } |
62 | 0 | Status status() const override { return status_; } |
63 | | |
64 | | private: |
65 | | Status status_; |
66 | | }; |
67 | | |
68 | | } // anonymous namespace |
69 | | |
70 | 0 | Iterator* NewEmptyIterator() { return new EmptyIterator(Status::OK()); } |
71 | | |
72 | 0 | Iterator* NewErrorIterator(const Status& status) { |
73 | 0 | return new EmptyIterator(status); |
74 | 0 | } |
75 | | |
76 | | } // namespace leveldb |