table/iterator.cc

filter: Statementstmt 44.9% 22 / 49 Branchbran 25.0% 5 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 39.1% 27 / 69 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« table/merger.cc ↑ Summary db/db_iter.cc »
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 35 Iterator::Iterator() {
10 35 cleanup_.function = NULL;
11 35 cleanup_.next = NULL;
12 35 }
13  
14 0 Iterator::~Iterator() {
15 35 ▶ if (cleanup_.function != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (cleanup_.function != NULL) { 17 18 35
16 17 (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2);
17 17 ▶ for (Cleanup* c = cleanup_.next; c != NULL; ) {
Branch: 1 branch
BranchTrueFalseTotal
for (Cleanup* c = cleanup_.next; c != NULL; ) { 0 17 17
18 0 (*c->function)(c->arg1, c->arg2);
19 0 Cleanup* next = c->next;
20 0 ▶ delete c;
Branch: 1 branch
BranchTrueFalseTotal
delete c; 0 0 0
21 0 c = next;
22 }
23 }
24 0 }
25  
26 17 void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
27 17 ▶ assert(func != NULL);
Branch: 1 branch
BranchTrueFalseTotal
assert(func != NULL); 0 17 17
28 Cleanup* c;
29 17 ▶ if (cleanup_.function == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (cleanup_.function == NULL) { 17 0 17
30 17 c = &cleanup_;
31 } else {
32 0 c = new Cleanup;
33 0 c->next = cleanup_.next;
34 0 cleanup_.next = c;
35 }
36 17 c->function = func;
37 17 c->arg1 = arg1;
38 17 c->arg2 = arg2;
39 17 }
40  
41 namespace {
42 class EmptyIterator : public Iterator {
43 public:
44 0 ▶ EmptyIterator(const Status& s) : status_(s) { }
Branch: 1 branch
BranchTrueFalseTotal
EmptyIterator(const Status& s) : status_(s) { } 0 0 0
45 0 virtual bool Valid() const { return false; }
46 0 virtual void Seek(const Slice& target) { }
47 0 virtual void SeekToFirst() { }
48 0 virtual void SeekToLast() { }
49 0 virtual void Next() { assert(false); }
50 0 virtual void Prev() { assert(false); }
51 0 Slice key() const { assert(false); return Slice(); }
52 0 Slice value() const { assert(false); return Slice(); }
53 0 virtual Status status() const { return status_; }
54 private:
55 Status status_;
56 };
57 }
58  
59 0 Iterator* NewEmptyIterator() {
60 0 ▶ return new EmptyIterator(Status::OK());
Branch: 2 branches
BranchTrueFalseTotal
return new EmptyIterator(Status::OK()); 0 0 0
return new EmptyIterator(Status::OK()); 0 0 0
61 }
62  
63 0 Iterator* NewErrorIterator(const Status& status) {
64 0 ▶ return new EmptyIterator(status);
Branch: 2 branches
BranchTrueFalseTotal
return new EmptyIterator(status); 0 0 0
return new EmptyIterator(status); 0 0 0
65 }
66  
67 }
« table/merger.cc ↑ Summary db/db_iter.cc »