LCOV - code coverage report
Current view: top level - matcher - valuestreamdocument.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 37 42 88.1 %
Date: 2019-06-30 05:20:33 Functions: 5 6 83.3 %
Branches: 29 44 65.9 %

           Branch data     Line data    Source code
       1                 :            : /** @file valuestreamdocument.cc
       2                 :            :  * @brief A document which gets its values from a ValueStreamManager.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2009,2011,2014,2017 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #include <config.h>
      22                 :            : 
      23                 :            : #include "valuestreamdocument.h"
      24                 :            : 
      25                 :            : #include "backends/multi/multi_database.h"
      26                 :            : #include "omassert.h"
      27                 :            : 
      28                 :            : using namespace std;
      29                 :            : 
      30                 :            : static void
      31                 :     178516 : clear_valuelists(map<Xapian::valueno, ValueList *> & valuelists)
      32                 :            : {
      33                 :     178516 :     map<Xapian::valueno, ValueList *>::const_iterator i;
      34         [ +  + ]:     200048 :     for (i = valuelists.begin(); i != valuelists.end(); ++i) {
      35         [ +  + ]:      21532 :         delete i->second;
      36                 :            :     }
      37                 :     178516 :     valuelists.clear();
      38                 :     178516 : }
      39                 :            : 
      40                 :     300204 : ValueStreamDocument::~ValueStreamDocument()
      41                 :            : {
      42         [ +  + ]:     150102 :     delete doc;
      43                 :     150102 :     clear_valuelists(valuelists);
      44         [ -  + ]:     150102 : }
      45                 :            : 
      46                 :            : void
      47                 :      28414 : ValueStreamDocument::new_shard(size_t n)
      48                 :            : {
      49                 :            :     AssertRel(n,>,0);
      50                 :            :     AssertRel(n,<,n_shards);
      51                 :      28414 :     current = unsigned(n);
      52                 :            :     // This method should only be called for a MultiDatabase.
      53                 :      28414 :     auto multidb = static_cast<MultiDatabase*>(db.internal.get());
      54                 :      28414 :     database = multidb->shards[n];
      55                 :            :     // Ensure set_document()'s "same docid" check doesn't misfire.
      56                 :      28414 :     did = 0;
      57                 :      28414 :     clear_valuelists(valuelists);
      58                 :      28414 : }
      59                 :            : 
      60                 :            : string
      61                 :      90687 : ValueStreamDocument::fetch_value(Xapian::valueno slot) const
      62                 :            : {
      63         [ +  - ]:      90687 :     pair<map<Xapian::valueno, ValueList *>::iterator, bool> ret;
      64 [ +  - ][ +  - ]:      90687 :     ret = valuelists.insert(make_pair(slot, static_cast<ValueList*>(NULL)));
      65                 :            :     ValueList * vl;
      66         [ +  + ]:      90687 :     if (ret.second) {
      67                 :            :         // Entry didn't already exist, so open a value list for slot.
      68         [ +  - ]:      21532 :         vl = database->open_value_list(slot);
      69                 :      21532 :         ret.first->second = vl;
      70                 :            :     } else {
      71                 :      69155 :         vl = ret.first->second;
      72         [ +  + ]:      69155 :         if (!vl) {
      73         [ +  - ]:         19 :             return string();
      74                 :            :         }
      75                 :            :     }
      76                 :            : 
      77 [ +  - ][ +  + ]:      90668 :     if (vl->check(did)) {
      78 [ +  - ][ +  + ]:      90468 :         if (vl->at_end()) {
      79         [ +  - ]:          6 :             delete vl;
      80                 :          6 :             ret.first->second = NULL;
      81 [ +  - ][ +  + ]:      90462 :         } else if (vl->get_docid() == did) {
      82         [ +  - ]:      90396 :             return vl->get_value();
      83                 :            :         }
      84                 :            :     }
      85                 :            : 
      86         [ +  - ]:      90687 :     return string();
      87                 :            : }
      88                 :            : 
      89                 :            : void
      90                 :          0 : ValueStreamDocument::fetch_all_values(map<Xapian::valueno, string> & v) const
      91                 :            : {
      92         [ #  # ]:          0 :     if (!doc) {
      93                 :          0 :         doc = database->open_document(did, true);
      94                 :            :     }
      95                 :          0 :     doc->fetch_all_values(v);
      96                 :          0 : }
      97                 :            : 
      98                 :            : string
      99                 :       5854 : ValueStreamDocument::fetch_data() const
     100                 :            : {
     101         [ +  - ]:       5854 :     if (!doc) {
     102                 :       5854 :         doc = database->open_document(did, true);
     103                 :            :     }
     104                 :       5854 :     return doc->fetch_data();
     105                 :            : }

Generated by: LCOV version 1.11