Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4591fb1

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 parent74b667a commit4591fb1

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_toffset;
9697

9798
re_comp_flagsflags;
98-
99-
/* text type info */
100-
Oidparam_type;
101-
int16typlen;
102-
booltypbyval;
103-
chartypalign;
10499
}regexp_matches_ctx;
105100

106101
typedefstructregexp_split_ctx
@@ -119,8 +114,7 @@ typedef struct regexp_split_ctx
119114
staticintnum_res=0;/* # of cached re's */
120115
staticcached_re_strre_array[MAX_CACHED_RES];/* cached re's */
121116

122-
staticregexp_matches_ctx*setup_regexp_matches(FunctionCallInfofcinfo,
123-
text*orig_str,text*pattern,
117+
staticregexp_matches_ctx*setup_regexp_matches(text*orig_str,text*pattern,
124118
text*flags);
125119
staticArrayType*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
staticregexp_matches_ctx*
825-
setup_regexp_matches(FunctionCallInfofcinfo,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
returnconstruct_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-
Oidparam_type;
980968
intnitems;
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)

[8]ページ先頭

©2009-2025 Movatter.jp