LCOV - code coverage report
Current view: top level - src/leveldb/table - iterator_wrapper.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 41 57 71.9 %
Date: 2022-04-21 14:51:19 Functions: 13 15 86.7 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 4 4 100.0 %

           Branch data     Line data    Source code
#       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                 :            : #ifndef STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_
#       6                 :            : #define STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_
#       7                 :            : 
#       8                 :            : #include "leveldb/iterator.h"
#       9                 :            : #include "leveldb/slice.h"
#      10                 :            : 
#      11                 :            : namespace leveldb {
#      12                 :            : 
#      13                 :            : // A internal wrapper class with an interface similar to Iterator that
#      14                 :            : // caches the valid() and key() results for an underlying iterator.
#      15                 :            : // This can help avoid virtual function calls and also gives better
#      16                 :            : // cache locality.
#      17                 :            : class IteratorWrapper {
#      18                 :            :  public:
#      19                 :       3262 :   IteratorWrapper() : iter_(nullptr), valid_(false) {}
#      20                 :       6915 :   explicit IteratorWrapper(Iterator* iter) : iter_(nullptr) { Set(iter); }
#      21                 :      10178 :   ~IteratorWrapper() { delete iter_; }
#      22                 :     174991 :   Iterator* iter() const { return iter_; }
#      23                 :            : 
#      24                 :            :   // Takes ownership of "iter" and will delete it when destroyed, or
#      25                 :            :   // when Set() is invoked again.
#      26                 :      17720 :   void Set(Iterator* iter) {
#      27                 :      17720 :     delete iter_;
#      28                 :      17720 :     iter_ = iter;
#      29         [ +  + ]:      17720 :     if (iter_ == nullptr) {
#      30                 :       6228 :       valid_ = false;
#      31                 :      11492 :     } else {
#      32                 :      11492 :       Update();
#      33                 :      11492 :     }
#      34                 :      17720 :   }
#      35                 :            : 
#      36                 :            :   // Iterator interface methods
#      37                 :    2474925 :   bool Valid() const { return valid_; }
#      38                 :     772741 :   Slice key() const {
#      39                 :     772741 :     assert(Valid());
#      40                 :          0 :     return key_;
#      41                 :     772741 :   }
#      42                 :     469814 :   Slice value() const {
#      43                 :     469814 :     assert(Valid());
#      44                 :          0 :     return iter_->value();
#      45                 :     469814 :   }
#      46                 :            :   // Methods below require iter() != nullptr
#      47                 :       6592 :   Status status() const {
#      48                 :       6592 :     assert(iter_);
#      49                 :          0 :     return iter_->status();
#      50                 :       6592 :   }
#      51                 :     286568 :   void Next() {
#      52                 :     286568 :     assert(iter_);
#      53                 :          0 :     iter_->Next();
#      54                 :     286568 :     Update();
#      55                 :     286568 :   }
#      56                 :          0 :   void Prev() {
#      57                 :          0 :     assert(iter_);
#      58                 :          0 :     iter_->Prev();
#      59                 :          0 :     Update();
#      60                 :          0 :   }
#      61                 :       5786 :   void Seek(const Slice& k) {
#      62                 :       5786 :     assert(iter_);
#      63                 :          0 :     iter_->Seek(k);
#      64                 :       5786 :     Update();
#      65                 :       5786 :   }
#      66                 :       4614 :   void SeekToFirst() {
#      67                 :       4614 :     assert(iter_);
#      68                 :          0 :     iter_->SeekToFirst();
#      69                 :       4614 :     Update();
#      70                 :       4614 :   }
#      71                 :          0 :   void SeekToLast() {
#      72                 :          0 :     assert(iter_);
#      73                 :          0 :     iter_->SeekToLast();
#      74                 :          0 :     Update();
#      75                 :          0 :   }
#      76                 :            : 
#      77                 :            :  private:
#      78                 :     308468 :   void Update() {
#      79                 :     308468 :     valid_ = iter_->Valid();
#      80         [ +  + ]:     308468 :     if (valid_) {
#      81                 :     289454 :       key_ = iter_->key();
#      82                 :     289454 :     }
#      83                 :     308468 :   }
#      84                 :            : 
#      85                 :            :   Iterator* iter_;
#      86                 :            :   bool valid_;
#      87                 :            :   Slice key_;
#      88                 :            : };
#      89                 :            : 
#      90                 :            : }  // namespace leveldb
#      91                 :            : 
#      92                 :            : #endif  // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a