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

Commit980341b

Browse files
committed
Avoid using text_to_cstring() in levenshtein functions.
Operating directly on the underlying varlena saves palloc and memcpyoverhead, which testing shows to be significant.Extracted from a larger patch by Alexander Korotkov.
1 parentaab353a commit980341b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

‎contrib/fuzzystrmatch/fuzzystrmatch.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Joe Conway <mail@joeconway.com>
77
*
8-
* $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.32 2010/01/02 16:57:32 momjian Exp $
8+
* $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.33 2010/07/29 20:11:48 rhaas Exp $
99
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
1010
* ALL RIGHTS RESERVED;
1111
*
@@ -90,7 +90,7 @@ soundex_code(char letter)
9090
*/
9191
#defineMAX_LEVENSHTEIN_STRLEN255
9292

93-
staticintlevenshtein_internal(constchar*s,constchar*t,
93+
staticintlevenshtein_internal(text*s,text*t,
9494
intins_c,intdel_c,intsub_c);
9595

9696

@@ -191,7 +191,7 @@ getcode(char c)
191191
* cases, but your mileage may vary.
192192
*/
193193
staticint
194-
levenshtein_internal(constchar*s,constchar*t,
194+
levenshtein_internal(text*s,text*t,
195195
intins_c,intdel_c,intsub_c)
196196
{
197197
intm,
@@ -203,8 +203,8 @@ levenshtein_internal(const char *s, const char *t,
203203
constchar*x;
204204
constchar*y;
205205

206-
m=strlen(s);
207-
n=strlen(t);
206+
m=VARSIZE_ANY_EXHDR(s);
207+
n=VARSIZE_ANY_EXHDR(t);
208208

209209
/*
210210
* We can transform an empty s into t with n insertions, or a non-empty t
@@ -244,7 +244,7 @@ levenshtein_internal(const char *s, const char *t,
244244
prev[i]=i*del_c;
245245

246246
/* Loop through rows of the notional array */
247-
for (y=t,j=1;j<n;y++,j++)
247+
for (y=VARDATA_ANY(t),j=1;j<n;y++,j++)
248248
{
249249
int*temp;
250250

@@ -254,7 +254,7 @@ levenshtein_internal(const char *s, const char *t,
254254
*/
255255
curr[0]=j*ins_c;
256256

257-
for (x=s,i=1;i<m;x++,i++)
257+
for (x=VARDATA_ANY(s),i=1;i<m;x++,i++)
258258
{
259259
intins;
260260
intdel;
@@ -288,8 +288,8 @@ PG_FUNCTION_INFO_V1(levenshtein_with_costs);
288288
Datum
289289
levenshtein_with_costs(PG_FUNCTION_ARGS)
290290
{
291-
char*src=TextDatumGetCString(PG_GETARG_DATUM(0));
292-
char*dst=TextDatumGetCString(PG_GETARG_DATUM(1));
291+
text*src=PG_GETARG_TEXT_PP(0);
292+
text*dst=PG_GETARG_TEXT_PP(1);
293293
intins_c=PG_GETARG_INT32(2);
294294
intdel_c=PG_GETARG_INT32(3);
295295
intsub_c=PG_GETARG_INT32(4);
@@ -302,8 +302,8 @@ PG_FUNCTION_INFO_V1(levenshtein);
302302
Datum
303303
levenshtein(PG_FUNCTION_ARGS)
304304
{
305-
char*src=TextDatumGetCString(PG_GETARG_DATUM(0));
306-
char*dst=TextDatumGetCString(PG_GETARG_DATUM(1));
305+
text*src=PG_GETARG_TEXT_PP(0);
306+
text*dst=PG_GETARG_TEXT_PP(1);
307307

308308
PG_RETURN_INT32(levenshtein_internal(src,dst,1,1,1));
309309
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp