LCOV - code coverage report
Current view: top level - sql/common - sql_changeset.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 30 90.0 %
Date: 2021-10-13 02:24:04 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : #include "monetdb_config.h"
      10             : #include "sql_catalog.h"
      11             : 
      12             : void
      13        5884 : cs_new(changeset * cs, sql_allocator *sa, fdestroy destroy)
      14             : {
      15        5884 :         *cs = (changeset) {
      16             :                 .sa = sa,
      17             :                 .destroy = destroy,
      18             :         };
      19        5884 : }
      20             : 
      21             : void
      22        5884 : cs_destroy(changeset * cs, void *data)
      23             : {
      24        5884 :         if (cs->set) {
      25          34 :                 list_destroy2(cs->set, data);
      26          34 :                 cs->set = NULL;
      27             :         }
      28        5884 :         if (cs->dset) {
      29           0 :                 list_destroy2(cs->dset, data);
      30           0 :                 cs->dset = NULL;
      31             :         }
      32        5884 : }
      33             : 
      34             : void
      35          50 : cs_add(changeset * cs, void *elm, bool isnew)
      36             : {
      37          50 :         if (!cs->set)
      38          34 :                 cs->set = list_new(cs->sa, cs->destroy);
      39          50 :         list_append(cs->set, elm);
      40          50 :         if (isnew && !cs->nelm)
      41          49 :                 cs->nelm = cs->set->t;
      42          50 : }
      43             : 
      44             : void
      45          30 : cs_del(changeset * cs, void *gdata, node *elm, bool isnew)
      46             : {
      47          30 :         if (cs->nelm == elm)
      48           8 :                 cs->nelm = elm->next;
      49          30 :         if (isnew) {    /* remove just added */
      50           0 :                 list_remove_node(cs->set, gdata, elm);
      51             :         } else {
      52          30 :                 if (!cs->dset)
      53          30 :                         cs->dset = list_new(cs->sa, cs->destroy);
      54          30 :                 list_move_data(cs->set, cs->dset, elm->data);
      55             :         }
      56          30 : }
      57             : 
      58             : int
      59       80848 : cs_size(changeset * cs)
      60             : {
      61       80848 :         if (cs->set)
      62        1005 :                 return list_length(cs->set);
      63             :         return 0;
      64             : }
      65             : 

Generated by: LCOV version 1.14