diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-02-19 18:57:38 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-02-19 18:58:23 -0500 |
commit | 27af91438b68f46f4015853b6f75c6f5c3a8650c (patch) | |
tree | 3d3edbeb3f1146775a2a17de86394c0ba49d843f /src/backend/regex/regc_cvec.c | |
parent | 2f582f76b1945929ff07116cd4639747ce9bb8a1 (diff) | |
download | postgresql-27af91438b68f46f4015853b6f75c6f5c3a8650c.tar.gz postgresql-27af91438b68f46f4015853b6f75c6f5c3a8650c.zip |
Create the beginnings of internals documentation for the regex code.
Create src/backend/regex/README to hold an implementation overview of
the regex package, and fill it in with some preliminary notes about
the code's DFA/NFA processing and colormap management. Much more to
do there of course.
Also, improve some code comments around the colormap and cvec code.
No functional changes except to add one missing assert.
Diffstat (limited to 'src/backend/regex/regc_cvec.c')
-rw-r--r-- | src/backend/regex/regc_cvec.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/backend/regex/regc_cvec.c b/src/backend/regex/regc_cvec.c index fb6f06b5243..580a693161e 100644 --- a/src/backend/regex/regc_cvec.c +++ b/src/backend/regex/regc_cvec.c @@ -77,6 +77,7 @@ static void addchr(struct cvec * cv, /* character vector */ chr c) /* character to add */ { + assert(cv->nchrs < cv->chrspace); cv->chrs[cv->nchrs++] = (chr) c; } @@ -95,17 +96,27 @@ addrange(struct cvec * cv, /* character vector */ } /* - * getcvec - get a cvec, remembering it as v->cv + * getcvec - get a transient cvec, initialized to empty + * + * The returned cvec is valid only until the next call of getcvec, which + * typically will recycle the space. Callers should *not* free the cvec + * explicitly; it will be cleaned up when the struct vars is destroyed. + * + * This is typically used while interpreting bracket expressions. In that + * usage the cvec is only needed momentarily until we build arcs from it, + * so transientness is a convenient behavior. */ static struct cvec * getcvec(struct vars * v, /* context */ int nchrs, /* to hold this many chrs... */ int nranges) /* ... and this many ranges */ { + /* recycle existing transient cvec if large enough */ if (v->cv != NULL && nchrs <= v->cv->chrspace && nranges <= v->cv->rangespace) return clearcvec(v->cv); + /* nope, make a new one */ if (v->cv != NULL) freecvec(v->cv); v->cv = newcvec(nchrs, nranges); |