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

Commit8816af6

Browse files
committed
Minor refactoring of btree_gist code.
The gbt_var_key_copy function was doing two different things depending onthe boolean argument. Seems cleaner to have two separate functions.Remove unused argument from gbt_num_compress.
1 parent55b59ed commit8816af6

17 files changed

+50
-53
lines changed

‎contrib/btree_gist/btree_bit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ gbt_bit_l2n(GBT_VARKEY *leaf)
9999

100100
o=gbt_bit_xfrm(r.lower);
101101
r.upper=r.lower=o;
102-
out=gbt_var_key_copy(&r, TRUE);
102+
out=gbt_var_key_copy(&r);
103103
pfree(o);
104104

105105
returnout;

‎contrib/btree_gist/btree_cash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ Datum
119119
gbt_cash_compress(PG_FUNCTION_ARGS)
120120
{
121121
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
122-
GISTENTRY*retval=NULL;
123122

124-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
123+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
125124
}
126125

127126

‎contrib/btree_gist/btree_date.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ Datum
130130
gbt_date_compress(PG_FUNCTION_ARGS)
131131
{
132132
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
133-
GISTENTRY*retval=NULL;
134133

135-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
134+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
136135
}
137136

138137

‎contrib/btree_gist/btree_float4.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ Datum
112112
gbt_float4_compress(PG_FUNCTION_ARGS)
113113
{
114114
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
115-
GISTENTRY*retval=NULL;
116115

117-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
116+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
118117
}
119118

120119

‎contrib/btree_gist/btree_float8.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ Datum
119119
gbt_float8_compress(PG_FUNCTION_ARGS)
120120
{
121121
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
122-
GISTENTRY*retval=NULL;
123122

124-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
123+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
125124
}
126125

127126

‎contrib/btree_gist/btree_int2.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ Datum
119119
gbt_int2_compress(PG_FUNCTION_ARGS)
120120
{
121121
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
122-
GISTENTRY*retval=NULL;
123122

124-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
123+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
125124
}
126125

127126

‎contrib/btree_gist/btree_int4.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ Datum
120120
gbt_int4_compress(PG_FUNCTION_ARGS)
121121
{
122122
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
123-
GISTENTRY*retval=NULL;
124123

125-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
124+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
126125
}
127126

128127

‎contrib/btree_gist/btree_int8.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ Datum
120120
gbt_int8_compress(PG_FUNCTION_ARGS)
121121
{
122122
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
123-
GISTENTRY*retval=NULL;
124123

125-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
124+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
126125
}
127126

128127

‎contrib/btree_gist/btree_macaddr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ Datum
110110
gbt_macad_compress(PG_FUNCTION_ARGS)
111111
{
112112
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
113-
GISTENTRY*retval=NULL;
114113

115-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
114+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
116115
}
117116

118117

‎contrib/btree_gist/btree_numeric.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
170170
uk;
171171

172172
rk=gbt_var_key_readable(org);
173-
uni=PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
173+
uni=PointerGetDatum(gbt_var_key_copy(&rk));
174174
gbt_var_bin_union(&uni,newe,PG_GET_COLLATION(),&tinfo);
175175
ok=gbt_var_key_readable(org);
176176
uk=gbt_var_key_readable((GBT_VARKEY*)DatumGetPointer(uni));

‎contrib/btree_gist/btree_oid.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ Datum
120120
gbt_oid_compress(PG_FUNCTION_ARGS)
121121
{
122122
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
123-
GISTENTRY*retval=NULL;
124123

125-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
124+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
126125
}
127126

128127

‎contrib/btree_gist/btree_time.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ Datum
157157
gbt_time_compress(PG_FUNCTION_ARGS)
158158
{
159159
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
160-
GISTENTRY*retval=NULL;
161160

162-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
161+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
163162
}
164163

165164

‎contrib/btree_gist/btree_ts.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ Datum
212212
gbt_ts_compress(PG_FUNCTION_ARGS)
213213
{
214214
GISTENTRY*entry= (GISTENTRY*)PG_GETARG_POINTER(0);
215-
GISTENTRY*retval=NULL;
216215

217-
PG_RETURN_POINTER(gbt_num_compress(retval,entry,&tinfo));
216+
PG_RETURN_POINTER(gbt_num_compress(entry,&tinfo));
218217
}
219218

220219

‎contrib/btree_gist/btree_utils_num.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212

1313
GISTENTRY*
14-
gbt_num_compress(GISTENTRY*retval,GISTENTRY*entry,constgbtree_ninfo*tinfo)
14+
gbt_num_compress(GISTENTRY*entry,constgbtree_ninfo*tinfo)
1515
{
16+
GISTENTRY*retval;
17+
1618
if (entry->leafkey)
1719
{
1820
union

‎contrib/btree_gist/btree_utils_num.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ extern float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query,
128128
externGIST_SPLITVEC*gbt_num_picksplit(constGistEntryVector*entryvec,GIST_SPLITVEC*v,
129129
constgbtree_ninfo*tinfo);
130130

131-
externGISTENTRY*gbt_num_compress(GISTENTRY*retval,GISTENTRY*entry,
132-
constgbtree_ninfo*tinfo);
131+
externGISTENTRY*gbt_num_compress(GISTENTRY*entry,constgbtree_ninfo*tinfo);
133132

134133

135134
externvoid*gbt_num_union(GBT_NUMKEY*out,constGistEntryVector*entryvec,

‎contrib/btree_gist/btree_utils_var.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,37 @@ gbt_var_key_readable(const GBT_VARKEY *k)
6666
}
6767

6868

69+
/*
70+
* Create a leaf-entry to store in the index, from a single Datum.
71+
*/
72+
staticGBT_VARKEY*
73+
gbt_var_key_from_datum(conststructvarlena*u)
74+
{
75+
int32lowersize=VARSIZE(u);
76+
GBT_VARKEY*r;
77+
78+
r= (GBT_VARKEY*)palloc(lowersize+VARHDRSZ);
79+
memcpy(VARDATA(r),u,lowersize);
80+
SET_VARSIZE(r,lowersize+VARHDRSZ);
81+
82+
returnr;
83+
}
84+
85+
/*
86+
* Create an entry to store in the index, from lower and upper bound.
87+
*/
6988
GBT_VARKEY*
70-
gbt_var_key_copy(constGBT_VARKEY_R*u,boolforce_node)
89+
gbt_var_key_copy(constGBT_VARKEY_R*u)
7190
{
72-
GBT_VARKEY*r=NULL;
7391
int32lowersize=VARSIZE(u->lower);
7492
int32uppersize=VARSIZE(u->upper);
93+
GBT_VARKEY*r;
94+
95+
r= (GBT_VARKEY*)palloc0(INTALIGN(lowersize)+uppersize+VARHDRSZ);
96+
memcpy(VARDATA(r),u->lower,lowersize);
97+
memcpy(VARDATA(r)+INTALIGN(lowersize),u->upper,uppersize);
98+
SET_VARSIZE(r,INTALIGN(lowersize)+uppersize+VARHDRSZ);
7599

76-
if (u->lower==u->upper&& !force_node)
77-
{/* leaf key mode */
78-
r= (GBT_VARKEY*)palloc(lowersize+VARHDRSZ);
79-
memcpy(VARDATA(r),u->lower,lowersize);
80-
SET_VARSIZE(r,lowersize+VARHDRSZ);
81-
}
82-
else
83-
{/* node key mode */
84-
r= (GBT_VARKEY*)palloc0(INTALIGN(lowersize)+uppersize+VARHDRSZ);
85-
memcpy(VARDATA(r),u->lower,lowersize);
86-
memcpy(VARDATA(r)+INTALIGN(lowersize),u->upper,uppersize);
87-
SET_VARSIZE(r,INTALIGN(lowersize)+uppersize+VARHDRSZ);
88-
}
89100
returnr;
90101
}
91102

@@ -255,31 +266,28 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
255266
}
256267

257268
if (update)
258-
*u=PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
269+
*u=PointerGetDatum(gbt_var_key_copy(&nr));
259270
}
260271
else
261272
{
262273
nr.lower=eo.lower;
263274
nr.upper=eo.upper;
264-
*u=PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
275+
*u=PointerGetDatum(gbt_var_key_copy(&nr));
265276
}
266277
}
267278

268279

269-
270280
GISTENTRY*
271281
gbt_var_compress(GISTENTRY*entry,constgbtree_vinfo*tinfo)
272282
{
273283
GISTENTRY*retval;
274284

275285
if (entry->leafkey)
276286
{
277-
GBT_VARKEY*r=NULL;
278-
bytea*leaf= (bytea*)DatumGetPointer(PG_DETOAST_DATUM(entry->key));
279-
GBT_VARKEY_Ru;
287+
structvarlena*leaf=PG_DETOAST_DATUM(entry->key);
288+
GBT_VARKEY*r;
280289

281-
u.lower=u.upper=leaf;
282-
r=gbt_var_key_copy(&u, FALSE);
290+
r=gbt_var_key_from_datum(leaf);
283291

284292
retval=palloc(sizeof(GISTENTRY));
285293
gistentryinit(*retval,PointerGetDatum(r),
@@ -293,7 +301,6 @@ gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
293301
}
294302

295303

296-
297304
GBT_VARKEY*
298305
gbt_var_union(constGistEntryVector*entryvec,int32*size,Oidcollation,
299306
constgbtree_vinfo*tinfo)
@@ -308,7 +315,7 @@ gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation,
308315

309316
cur= (GBT_VARKEY*)DatumGetPointer(entryvec->vector[0].key);
310317
rk=gbt_var_key_readable(cur);
311-
out=PointerGetDatum(gbt_var_key_copy(&rk, TRUE));
318+
out=PointerGetDatum(gbt_var_key_copy(&rk));
312319

313320
for (i=1;i<numranges;i++)
314321
{

‎contrib/btree_gist/btree_utils_var.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ typedef struct
4747

4848
externGBT_VARKEY_Rgbt_var_key_readable(constGBT_VARKEY*k);
4949

50-
externGBT_VARKEY*gbt_var_key_copy(constGBT_VARKEY_R*u,boolforce_node);
50+
externGBT_VARKEY*gbt_var_key_copy(constGBT_VARKEY_R*u);
5151

5252
externGISTENTRY*gbt_var_compress(GISTENTRY*entry,constgbtree_vinfo*tinfo);
5353

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp