LCOV - differential code coverage report
Current view: top level - src/backend/regex - regc_cvec.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 95.0 % 40 38 2 38
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 6 6 6
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 95.0 % 40 38 2 38
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 100.0 % 6 6 6

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*
                                  2                 :  * Utility functions for handling cvecs
                                  3                 :  * This file is #included by regcomp.c.
                                  4                 :  *
                                  5                 :  * Copyright (c) 1998, 1999 Henry Spencer.  All rights reserved.
                                  6                 :  *
                                  7                 :  * Development of this software was funded, in part, by Cray Research Inc.,
                                  8                 :  * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
                                  9                 :  * Corporation, none of whom are responsible for the results.  The author
                                 10                 :  * thanks all of them.
                                 11                 :  *
                                 12                 :  * Redistribution and use in source and binary forms -- with or without
                                 13                 :  * modification -- are permitted for any purpose, provided that
                                 14                 :  * redistributions in source form retain this entire copyright notice and
                                 15                 :  * indicate the origin and nature of any modifications.
                                 16                 :  *
                                 17                 :  * I'd appreciate being given credit for this package in the documentation
                                 18                 :  * of software which uses it, but that is not a requirement.
                                 19                 :  *
                                 20                 :  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                                 21                 :  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                                 22                 :  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
                                 23                 :  * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                                 24                 :  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                                 25                 :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                                 26                 :  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                                 27                 :  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                                 28                 :  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                                 29                 :  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                                 30                 :  *
                                 31                 :  * src/backend/regex/regc_cvec.c
                                 32                 :  *
                                 33                 :  */
                                 34                 : 
                                 35                 : /*
                                 36                 :  * Notes:
                                 37                 :  * Only (selected) functions in _this_ file should treat the chr arrays
                                 38                 :  * of a cvec as non-constant.
                                 39                 :  */
                                 40                 : 
                                 41                 : /*
                                 42                 :  * newcvec - allocate a new cvec
                                 43                 :  */
                                 44                 : static struct cvec *
 7368 tgl                        45 CBC        3934 : newcvec(int nchrs,              /* to hold this many chrs... */
                                 46                 :         int nranges)            /* ... and this many ranges */
                                 47                 : {
 5533                            48            3934 :     size_t      nc = (size_t) nchrs + (size_t) nranges * 2;
                                 49            3934 :     size_t      n = sizeof(struct cvec) + nc * sizeof(chr);
                                 50            3934 :     struct cvec *cv = (struct cvec *) MALLOC(n);
                                 51                 : 
 7188 bruce                      52            3934 :     if (cv == NULL)
 7188 bruce                      53 UBC           0 :         return NULL;
 7188 bruce                      54 CBC        3934 :     cv->chrspace = nchrs;
 5533 tgl                        55            3934 :     cv->chrs = (chr *) (((char *) cv) + sizeof(struct cvec));
                                 56            3934 :     cv->ranges = cv->chrs + nchrs;
 7188 bruce                      57            3934 :     cv->rangespace = nranges;
                                 58            3934 :     return clearcvec(cv);
                                 59                 : }
                                 60                 : 
                                 61                 : /*
                                 62                 :  * clearcvec - clear a possibly-new cvec
                                 63                 :  * Returns pointer as convenience.
                                 64                 :  */
                                 65                 : static struct cvec *
 2118 tgl                        66            5378 : clearcvec(struct cvec *cv)
                                 67                 : {
 7188 bruce                      68            5378 :     assert(cv != NULL);
                                 69            5378 :     cv->nchrs = 0;
                                 70            5378 :     cv->nranges = 0;
 2407 tgl                        71            5378 :     cv->cclasscode = -1;
 7188 bruce                      72            5378 :     return cv;
                                 73                 : }
                                 74                 : 
                                 75                 : /*
                                 76                 :  * addchr - add a chr to a cvec
                                 77                 :  */
                                 78                 : static void
 2118 tgl                        79            2116 : addchr(struct cvec *cv,         /* character vector */
                                 80                 :        chr c)                   /* character to add */
                                 81                 : {
 4067                            82            2116 :     assert(cv->nchrs < cv->chrspace);
 2424                            83            2116 :     cv->chrs[cv->nchrs++] = c;
 7368                            84            2116 : }
                                 85                 : 
                                 86                 : /*
                                 87                 :  * addrange - add a range to a cvec
                                 88                 :  */
                                 89                 : static void
 2118                            90             540 : addrange(struct cvec *cv,       /* character vector */
                                 91                 :          chr from,              /* first character of range */
                                 92                 :          chr to)                /* last character of range */
                                 93                 : {
 7188 bruce                      94             540 :     assert(cv->nranges < cv->rangespace);
 2424 tgl                        95             540 :     cv->ranges[cv->nranges * 2] = from;
                                 96             540 :     cv->ranges[cv->nranges * 2 + 1] = to;
 7188 bruce                      97             540 :     cv->nranges++;
 7368 tgl                        98             540 : }
                                 99                 : 
                                100                 : /*
                                101                 :  * getcvec - get a transient cvec, initialized to empty
                                102                 :  *
                                103                 :  * The returned cvec is valid only until the next call of getcvec, which
                                104                 :  * typically will recycle the space.  Callers should *not* free the cvec
                                105                 :  * explicitly; it will be cleaned up when the struct vars is destroyed.
                                106                 :  *
                                107                 :  * This is typically used while interpreting bracket expressions.  In that
                                108                 :  * usage the cvec is only needed momentarily until we build arcs from it,
                                109                 :  * so transientness is a convenient behavior.
                                110                 :  */
                                111                 : static struct cvec *
 2118                           112            1445 : getcvec(struct vars *v,         /* context */
                                113                 :         int nchrs,              /* to hold this many chrs... */
                                114                 :         int nranges)            /* ... and this many ranges */
                                115                 : {
                                116                 :     /* recycle existing transient cvec if large enough */
 7188 bruce                     117            1445 :     if (v->cv != NULL && nchrs <= v->cv->chrspace &&
 5533 tgl                       118            1444 :         nranges <= v->cv->rangespace)
 7188 bruce                     119            1444 :         return clearcvec(v->cv);
                                120                 : 
                                121                 :     /* nope, make a new one */
                                122               1 :     if (v->cv != NULL)
                                123               1 :         freecvec(v->cv);
 5533 tgl                       124               1 :     v->cv = newcvec(nchrs, nranges);
 7188 bruce                     125               1 :     if (v->cv == NULL)
 7188 bruce                     126 UBC           0 :         ERR(REG_ESPACE);
                                127                 : 
 7188 bruce                     128 CBC           1 :     return v->cv;
                                129                 : }
                                130                 : 
                                131                 : /*
                                132                 :  * freecvec - free a cvec
                                133                 :  */
                                134                 : static void
 2118 tgl                       135            3934 : freecvec(struct cvec *cv)
                                136                 : {
 7188 bruce                     137            3934 :     FREE(cv);
 7368 tgl                       138            3934 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a