aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/varlena.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-05-02 20:41:37 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-05-02 20:41:37 -0400
commit23c6eb03360d270051bf7dcb289ecb0cd114d29f (patch)
treed776860b1c41b1669683ebb4d2b566434793b3e4 /src/backend/utils/adt/varlena.c
parent9209e07605afe0349660447f20d83ef165cdd0ae (diff)
downloadpostgresql-23c6eb03360d270051bf7dcb289ecb0cd114d29f.tar.gz
postgresql-23c6eb03360d270051bf7dcb289ecb0cd114d29f.zip
Remove create_singleton_array(), hard-coding the case in its sole caller.
create_singleton_array() was not really as useful as we perhaps thought when we added it. It had never accreted more than one call site, and is only saving a dozen lines of code at that one, which is considerably less bulk than the function itself. Moreover, because of its insistence on using 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_extra uses could be needed within a single query, in the seldom-tested case that the field separator varies during the query. The same objection seems likely to apply to any other potential caller. The replacement code is a bit uglier, because it hardwires knowledge of the storage parameters of type TEXT, but it's not like we haven't got dozens or hundreds of other places that do the same. Uglier seems like a good tradeoff for smaller, faster, and safer. Per discussion with Neha Khatri. Discussion: https://postgr.es/m/CAFO0U+_fS5SRhzq6uPG+4fbERhoA9N2+nPrtvaC9mmeWivxbsA@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/varlena.c')
-rw-r--r--src/backend/utils/adt/varlena.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index c74c890b9b5..0b0032787b2 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -4218,12 +4218,23 @@ text_to_array_internal(PG_FUNCTION_ARGS)
*/
if (fldsep_len < 1)
{
+ Datum elems[1];
+ bool nulls[1];
+ int dims[1];
+ int lbs[1];
+
text_position_cleanup(&state);
/* single element can be a NULL too */
is_null = null_string ? text_isequal(inputstring, null_string) : false;
- PG_RETURN_ARRAYTYPE_P(create_singleton_array(fcinfo, TEXTOID,
- PointerGetDatum(inputstring),
- is_null, 1));
+
+ elems[0] = PointerGetDatum(inputstring);
+ nulls[0] = is_null;
+ dims[0] = 1;
+ lbs[0] = 1;
+ /* XXX: this hardcodes assumptions about the text type */
+ PG_RETURN_ARRAYTYPE_P(construct_md_array(elems, nulls,
+ 1, dims, lbs,
+ TEXTOID, -1, false, 'i'));
}
start_posn = 1;