Skip to content

Commit 4591fb1

Browse files
author
Neil Conway
committed
Code cleanup for the new regexp UDFs: we can hardcode the OID and some
properties of the "text" type, and then simplify the code accordingly. Patch from Jeremy Drake.
1 parent 74b667a commit 4591fb1

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/backend/utils/adt/regexp.c

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.70 2007/03/20 05:44:59 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.71 2007/03/28 22:59:37 neilc Exp $
1212
*
1313
* Alistair Crooks added the code for the regex caching
1414
* agc - cached the regular expressions used - there's a good chance
@@ -30,6 +30,7 @@
3030
#include "postgres.h"
3131

3232
#include "access/heapam.h"
33+
#include "catalog/pg_type.h"
3334
#include "funcapi.h"
3435
#include "regex/regex.h"
3536
#include "utils/builtins.h"
@@ -95,12 +96,6 @@ typedef struct regexp_matches_ctx
9596
size_t offset;
9697

9798
re_comp_flags flags;
98-
99-
/* text type info */
100-
Oid param_type;
101-
int16 typlen;
102-
bool typbyval;
103-
char typalign;
10499
} regexp_matches_ctx;
105100

106101
typedef struct regexp_split_ctx
@@ -119,8 +114,7 @@ typedef struct regexp_split_ctx
119114
static int num_res = 0; /* # of cached re's */
120115
static cached_re_str re_array[MAX_CACHED_RES]; /* cached re's */
121116

122-
static regexp_matches_ctx *setup_regexp_matches(FunctionCallInfo fcinfo,
123-
text *orig_str, text *pattern,
117+
static regexp_matches_ctx *setup_regexp_matches(text *orig_str, text *pattern,
124118
text *flags);
125119
static ArrayType *perform_regexp_matches(regexp_matches_ctx *matchctx);
126120

@@ -760,8 +754,8 @@ regexp_matches(PG_FUNCTION_ARGS)
760754
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
761755

762756
/* be sure to copy the input string into the multi-call ctx */
763-
matchctx = setup_regexp_matches(fcinfo, PG_GETARG_TEXT_P_COPY(0),
764-
pattern, flags);
757+
matchctx = setup_regexp_matches(PG_GETARG_TEXT_P_COPY(0), pattern,
758+
flags);
765759

766760
MemoryContextSwitchTo(oldcontext);
767761
funcctx->user_fctx = (void *) matchctx;
@@ -822,7 +816,7 @@ regexp_matches_no_flags(PG_FUNCTION_ARGS)
822816
}
823817

824818
static regexp_matches_ctx *
825-
setup_regexp_matches(FunctionCallInfo fcinfo, text *orig_str, text *pattern, text *flags)
819+
setup_regexp_matches(text *orig_str, text *pattern, text *flags)
826820
{
827821
regexp_matches_ctx *matchctx = palloc(sizeof(regexp_matches_ctx));
828822

@@ -835,11 +829,6 @@ setup_regexp_matches(FunctionCallInfo fcinfo, text *orig_str, text *pattern, tex
835829
matchctx->pmatch = palloc(sizeof(regmatch_t) * (matchctx->cpattern->re_nsub + 1));
836830
matchctx->offset = 0;
837831

838-
/* get text type oid, too lazy to do it some other way */
839-
matchctx->param_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
840-
get_typlenbyvalalign(matchctx->param_type, &matchctx->typlen,
841-
&matchctx->typbyval, &matchctx->typalign);
842-
843832
matchctx->wide_str = palloc(sizeof(pg_wchar) * (matchctx->orig_len + 1));
844833
matchctx->wide_len = pg_mb2wchar_with_len(VARDATA(matchctx->orig_str),
845834
matchctx->wide_str, matchctx->orig_len);
@@ -915,9 +904,9 @@ perform_regexp_matches(regexp_matches_ctx *matchctx)
915904
dims[0] = 1;
916905
}
917906

907+
/* XXX: this hardcodes assumptions about the text type */
918908
return construct_md_array(elems, nulls, ndims, dims, lbs,
919-
matchctx->param_type, matchctx->typlen,
920-
matchctx->typbyval, matchctx->typalign);
909+
TEXTOID, -1, false, 'i');
921910
}
922911

923912
Datum
@@ -976,16 +965,12 @@ Datum regexp_split_to_array(PG_FUNCTION_ARGS)
976965
{
977966
ArrayBuildState *astate = NULL;
978967
regexp_split_ctx *splitctx;
979-
Oid param_type;
980968
int nitems;
981969

982970
splitctx = setup_regexp_split(PG_GETARG_TEXT_P(0),
983971
PG_GETARG_TEXT_P(1),
984972
PG_GETARG_TEXT_P_IF_EXISTS(2));
985973

986-
/* get text type oid, too lazy to do it some other way */
987-
param_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
988-
989974
for (nitems = 0; splitctx->offset < splitctx->wide_len; nitems++)
990975
{
991976
if (nitems > splitctx->wide_len)
@@ -995,7 +980,7 @@ Datum regexp_split_to_array(PG_FUNCTION_ARGS)
995980
astate = accumArrayResult(astate,
996981
get_next_split(splitctx),
997982
false,
998-
param_type,
983+
TEXTOID,
999984
CurrentMemoryContext);
1000985
}
1001986

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy