LCOV - code coverage report
Current view: top level - src/leveldb/table - iterator.cc (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 61.0 % 41 25
Test Date: 2026-02-04 05:05:50 Functions: 55.6 % 18 10
Branches: 45.0 % 20 9

             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                 :             : #include "leveldb/iterator.h"
       6                 :             : 
       7                 :             : namespace leveldb {
       8                 :             : 
       9                 :     2360777 : Iterator::Iterator() {
      10                 :     2360777 :   cleanup_head_.function = nullptr;
      11                 :     2360777 :   cleanup_head_.next = nullptr;
      12                 :     2360777 : }
      13                 :             : 
      14                 :     2360777 : Iterator::~Iterator() {
      15         [ +  + ]:     2360777 :   if (!cleanup_head_.IsEmpty()) {
      16                 :      119928 :     cleanup_head_.Run();
      17         [ -  + ]:      119928 :     for (CleanupNode* node = cleanup_head_.next; node != nullptr;) {
      18                 :           0 :       node->Run();
      19                 :           0 :       CleanupNode* next_node = node->next;
      20                 :           0 :       delete node;
      21                 :           0 :       node = next_node;
      22                 :             :     }
      23                 :             :   }
      24                 :     2360777 : }
      25                 :             : 
      26                 :      119928 : void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
      27         [ -  + ]:      119928 :   assert(func != nullptr);
      28                 :      119928 :   CleanupNode* node;
      29         [ +  - ]:      119928 :   if (cleanup_head_.IsEmpty()) {
      30                 :      119928 :     node = &cleanup_head_;
      31                 :             :   } else {
      32                 :           0 :     node = new CleanupNode();
      33                 :           0 :     node->next = cleanup_head_.next;
      34                 :           0 :     cleanup_head_.next = node;
      35                 :             :   }
      36                 :      119928 :   node->function = func;
      37                 :      119928 :   node->arg1 = arg1;
      38                 :      119928 :   node->arg2 = arg2;
      39                 :      119928 : }
      40                 :             : 
      41                 :             : namespace {
      42                 :             : 
      43                 :             : class EmptyIterator : public Iterator {
      44                 :             :  public:
      45         [ +  - ]:           6 :   EmptyIterator(const Status& s) : status_(s) {}
      46         [ +  - ]:           9 :   ~EmptyIterator() override = default;
      47                 :             : 
      48                 :           5 :   bool Valid() const override { return false; }
      49                 :           3 :   void Seek(const Slice& target) override {}
      50                 :           0 :   void SeekToFirst() override {}
      51                 :           0 :   void SeekToLast() override {}
      52                 :           0 :   void Next() override { assert(false); }
      53                 :           0 :   void Prev() override { assert(false); }
      54                 :           0 :   Slice key() const override {
      55                 :           0 :     assert(false);
      56                 :             :     return Slice();
      57                 :             :   }
      58                 :           0 :   Slice value() const override {
      59                 :           0 :     assert(false);
      60                 :             :     return Slice();
      61                 :             :   }
      62         [ +  - ]:           2 :   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                 :           3 : Iterator* NewErrorIterator(const Status& status) {
      73         [ +  - ]:           3 :   return new EmptyIterator(status);
      74                 :             : }
      75                 :             : 
      76                 :             : }  // namespace leveldb
        

Generated by: LCOV version 2.0-1