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

Commit23c6eb0

Browse files
committed
Remove create_singleton_array(), hard-coding the case in its sole caller.
create_singleton_array() was not really as useful as we perhaps thoughtwhen we added it. It had never accreted more than one call site, and isonly saving a dozen lines of code at that one, which is considerably lessbulk than the function itself. Moreover, because of its insistence onusing the caller's fn_extra cache space, it's arguably a coding hazard.text_to_array_internal() does not currently use fn_extra in any other way,but if it did it would be subtly broken, since the conflicting fn_extrauses could be needed within a single query, in the seldom-tested case thatthe field separator varies during the query. The same objection seemslikely to apply to any other potential caller.The replacement code is a bit uglier, because it hardwires knowledge ofthe storage parameters of type TEXT, but it's not like we haven't gotdozens or hundreds of other places that do the same. Uglier seems likea good tradeoff for smaller, faster, and safer.Per discussion with Neha Khatri.Discussion:https://postgr.es/m/CAFO0U+_fS5SRhzq6uPG+4fbERhoA9N2+nPrtvaC9mmeWivxbsA@mail.gmail.com
1 parent9209e07 commit23c6eb0

File tree

3 files changed

+14
-85
lines changed

3 files changed

+14
-85
lines changed

‎src/backend/utils/adt/array_userfuncs.c

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -454,79 +454,6 @@ array_cat(PG_FUNCTION_ARGS)
454454
}
455455

456456

457-
/*
458-
* create_singleton_array - make a one-element array
459-
*
460-
* If desired, the caller can ask for it to be higher than one-dimensional.
461-
* Caller's fcinfo must be passed in, as we use fn_extra for caching.
462-
*/
463-
ArrayType*
464-
create_singleton_array(FunctionCallInfofcinfo,
465-
Oidelement_type,
466-
Datumelement,
467-
boolisNull,
468-
intndims)
469-
{
470-
Datumdvalues[1];
471-
boolnulls[1];
472-
int16typlen;
473-
booltypbyval;
474-
chartypalign;
475-
intdims[MAXDIM];
476-
intlbs[MAXDIM];
477-
inti;
478-
ArrayMetaState*my_extra;
479-
480-
if (ndims<1)
481-
ereport(ERROR,
482-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
483-
errmsg("invalid number of dimensions: %d",ndims)));
484-
if (ndims>MAXDIM)
485-
ereport(ERROR,
486-
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
487-
errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
488-
ndims,MAXDIM)));
489-
490-
dvalues[0]=element;
491-
nulls[0]=isNull;
492-
493-
for (i=0;i<ndims;i++)
494-
{
495-
dims[i]=1;
496-
lbs[i]=1;
497-
}
498-
499-
/*
500-
* We arrange to look up info about element type only once per series of
501-
* calls, assuming the element type doesn't change underneath us.
502-
*/
503-
my_extra= (ArrayMetaState*)fcinfo->flinfo->fn_extra;
504-
if (my_extra==NULL)
505-
{
506-
fcinfo->flinfo->fn_extra=MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
507-
sizeof(ArrayMetaState));
508-
my_extra= (ArrayMetaState*)fcinfo->flinfo->fn_extra;
509-
my_extra->element_type= ~element_type;
510-
}
511-
512-
if (my_extra->element_type!=element_type)
513-
{
514-
/* Get info about element type */
515-
get_typlenbyvalalign(element_type,
516-
&my_extra->typlen,
517-
&my_extra->typbyval,
518-
&my_extra->typalign);
519-
my_extra->element_type=element_type;
520-
}
521-
typlen=my_extra->typlen;
522-
typbyval=my_extra->typbyval;
523-
typalign=my_extra->typalign;
524-
525-
returnconstruct_md_array(dvalues,nulls,ndims,dims,lbs,element_type,
526-
typlen,typbyval,typalign);
527-
}
528-
529-
530457
/*
531458
* ARRAY_AGG(anynonarray) aggregate function
532459
*/

‎src/backend/utils/adt/varlena.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,12 +4218,23 @@ text_to_array_internal(PG_FUNCTION_ARGS)
42184218
*/
42194219
if (fldsep_len<1)
42204220
{
4221+
Datumelems[1];
4222+
boolnulls[1];
4223+
intdims[1];
4224+
intlbs[1];
4225+
42214226
text_position_cleanup(&state);
42224227
/* single element can be a NULL too */
42234228
is_null=null_string ?text_isequal(inputstring,null_string) : false;
4224-
PG_RETURN_ARRAYTYPE_P(create_singleton_array(fcinfo,TEXTOID,
4225-
PointerGetDatum(inputstring),
4226-
is_null,1));
4229+
4230+
elems[0]=PointerGetDatum(inputstring);
4231+
nulls[0]=is_null;
4232+
dims[0]=1;
4233+
lbs[0]=1;
4234+
/* XXX: this hardcodes assumptions about the text type */
4235+
PG_RETURN_ARRAYTYPE_P(construct_md_array(elems,nulls,
4236+
1,dims,lbs,
4237+
TEXTOID,-1, false,'i'));
42274238
}
42284239

42294240
start_posn=1;

‎src/include/utils/array.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,4 @@ extern ExpandedArrayHeader *DatumGetExpandedArrayX(Datum d,
443443
externAnyArrayType*DatumGetAnyArray(Datumd);
444444
externvoiddeconstruct_expanded_array(ExpandedArrayHeader*eah);
445445

446-
/*
447-
* prototypes for functions defined in array_userfuncs.c
448-
*/
449-
externArrayType*create_singleton_array(FunctionCallInfofcinfo,
450-
Oidelement_type,
451-
Datumelement,
452-
boolisNull,
453-
intndims);
454-
455446
#endif/* ARRAY_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp