aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/arrayfuncs.c161
-rw-r--r--src/backend/utils/adt/arrayutils.c5
-rw-r--r--src/backend/utils/adt/hbafuncs.c2
-rw-r--r--src/backend/utils/adt/json.c13
-rw-r--r--src/backend/utils/adt/jsonb.c13
-rw-r--r--src/backend/utils/adt/jsonb_gin.c4
-rw-r--r--src/backend/utils/adt/jsonb_op.c6
-rw-r--r--src/backend/utils/adt/jsonfuncs.c18
-rw-r--r--src/backend/utils/adt/lockfuncs.c10
-rw-r--r--src/backend/utils/adt/name.c6
-rw-r--r--src/backend/utils/adt/orderedsetaggs.c20
-rw-r--r--src/backend/utils/adt/pg_upgrade_support.c4
-rw-r--r--src/backend/utils/adt/ruleutils.c20
-rw-r--r--src/backend/utils/adt/tsvector_op.c19
-rw-r--r--src/backend/utils/adt/xml.c6
-rw-r--r--src/backend/utils/cache/evtcache.c3
-rw-r--r--src/backend/utils/fmgr/funcapi.c14
-rw-r--r--src/backend/utils/misc/guc.c14
18 files changed, 215 insertions, 123 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index 2570e5e6301..b0c37ede87d 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -3331,6 +3331,92 @@ construct_array(Datum *elems, int nelems,
}
/*
+ * Like construct_array(), where elmtype must be a built-in type, and
+ * elmlen/elmbyval/elmalign is looked up from hardcoded data. This is often
+ * useful when manipulating arrays from/for system catalogs.
+ */
+ArrayType *
+construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
+{
+ int elmlen;
+ bool elmbyval;
+ char elmalign;
+
+ switch (elmtype)
+ {
+ case CHAROID:
+ elmlen = 1;
+ elmbyval = true;
+ elmalign = TYPALIGN_CHAR;
+ break;
+
+ case CSTRINGOID:
+ elmlen = -2;
+ elmbyval = false;
+ elmalign = TYPALIGN_CHAR;
+ break;
+
+ case FLOAT4OID:
+ elmlen = sizeof(float4);
+ elmbyval = true;
+ elmalign = TYPALIGN_INT;
+ break;
+
+ case INT2OID:
+ elmlen = sizeof(int16);
+ elmbyval = true;
+ elmalign = TYPALIGN_SHORT;
+ break;
+
+ case INT4OID:
+ elmlen = sizeof(int32);
+ elmbyval = true;
+ elmalign = TYPALIGN_INT;
+ break;
+
+ case INT8OID:
+ elmlen = sizeof(int64);
+ elmbyval = FLOAT8PASSBYVAL;
+ elmalign = TYPALIGN_DOUBLE;
+ break;
+
+ case NAMEOID:
+ elmlen = NAMEDATALEN;
+ elmbyval = false;
+ elmalign = TYPALIGN_CHAR;
+ break;
+
+ case OIDOID:
+ case REGTYPEOID:
+ elmlen = sizeof(Oid);
+ elmbyval = true;
+ elmalign = TYPALIGN_INT;
+ break;
+
+ case TEXTOID:
+ elmlen = -1;
+ elmbyval = false;
+ elmalign = TYPALIGN_INT;
+ break;
+
+ case TIDOID:
+ elmlen = sizeof(ItemPointerData);
+ elmbyval = false;
+ elmalign = TYPALIGN_SHORT;
+ break;
+
+ default:
+ elog(ERROR, "type %u not supported by construct_array_builtin()", elmtype);
+ /* keep compiler quiet */
+ elmlen = 0;
+ elmbyval = false;
+ elmalign = 0;
+ }
+
+ return construct_array(elems, nelems, elmtype, elmlen, elmbyval, elmalign);
+}
+
+/*
* construct_md_array --- simple method for constructing an array object
* with arbitrary dimensions and possible NULLs
*
@@ -3483,9 +3569,9 @@ construct_empty_expanded_array(Oid element_type,
* be pointers into the array object.
*
* NOTE: it would be cleaner to look up the elmlen/elmbval/elmalign info
- * from the system catalogs, given the elmtype. However, in most current
- * uses the type is hard-wired into the caller and so we can save a lookup
- * cycle by hard-wiring the type info as well.
+ * from the system catalogs, given the elmtype. However, the caller is
+ * in a better position to cache this info across multiple uses, or even
+ * to hard-wire values if the element type is hard-wired.
*/
void
deconstruct_array(ArrayType *array,
@@ -3549,6 +3635,75 @@ deconstruct_array(ArrayType *array,
}
/*
+ * Like deconstruct_array(), where elmtype must be a built-in type, and
+ * elmlen/elmbyval/elmalign is looked up from hardcoded data. This is often
+ * useful when manipulating arrays from/for system catalogs.
+ */
+void
+deconstruct_array_builtin(ArrayType *array,
+ Oid elmtype,
+ Datum **elemsp, bool **nullsp, int *nelemsp)
+{
+ int elmlen;
+ bool elmbyval;
+ char elmalign;
+
+ switch (elmtype)
+ {
+ case CHAROID:
+ elmlen = 1;
+ elmbyval = true;
+ elmalign = TYPALIGN_CHAR;
+ break;
+
+ case CSTRINGOID:
+ elmlen = -2;
+ elmbyval = false;
+ elmalign = TYPALIGN_CHAR;
+ break;
+
+ case FLOAT8OID:
+ elmlen = sizeof(float8);
+ elmbyval = FLOAT8PASSBYVAL;
+ elmalign = TYPALIGN_DOUBLE;
+ break;
+
+ case INT2OID:
+ elmlen = sizeof(int16);
+ elmbyval = true;
+ elmalign = TYPALIGN_SHORT;
+ break;
+
+ case OIDOID:
+ elmlen = sizeof(Oid);
+ elmbyval = true;
+ elmalign = TYPALIGN_INT;
+ break;
+
+ case TEXTOID:
+ elmlen = -1;
+ elmbyval = false;
+ elmalign = TYPALIGN_INT;
+ break;
+
+ case TIDOID:
+ elmlen = sizeof(ItemPointerData);
+ elmbyval = false;
+ elmalign = TYPALIGN_SHORT;
+ break;
+
+ default:
+ elog(ERROR, "type %u not supported by deconstruct_array_builtin()", elmtype);
+ /* keep compiler quiet */
+ elmlen = 0;
+ elmbyval = false;
+ elmalign = 0;
+ }
+
+ deconstruct_array(array, elmtype, elmlen, elmbyval, elmalign, elemsp, nullsp, nelemsp);
+}
+
+/*
* array_contains_nulls --- detect whether an array has any null elements
*
* This gives an accurate answer, whereas testing ARR_HASNULL only tells
diff --git a/src/backend/utils/adt/arrayutils.c b/src/backend/utils/adt/arrayutils.c
index 464a37641e2..051169a149a 100644
--- a/src/backend/utils/adt/arrayutils.c
+++ b/src/backend/utils/adt/arrayutils.c
@@ -249,10 +249,7 @@ ArrayGetIntegerTypmods(ArrayType *arr, int *n)
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("typmod array must not contain nulls")));
- /* hardwired knowledge about cstring's representation details here */
- deconstruct_array(arr, CSTRINGOID,
- -2, false, TYPALIGN_CHAR,
- &elem_values, NULL, n);
+ deconstruct_array_builtin(arr, CSTRINGOID, &elem_values, NULL, n);
result = (int32 *) palloc(*n * sizeof(int32));
diff --git a/src/backend/utils/adt/hbafuncs.c b/src/backend/utils/adt/hbafuncs.c
index 9fe7b62c9a0..598259718c4 100644
--- a/src/backend/utils/adt/hbafuncs.c
+++ b/src/backend/utils/adt/hbafuncs.c
@@ -151,7 +151,7 @@ get_hba_options(HbaLine *hba)
Assert(noptions <= MAX_HBA_OPTIONS);
if (noptions > 0)
- return construct_array(options, noptions, TEXTOID, -1, false, TYPALIGN_INT);
+ return construct_array_builtin(options, noptions, TEXTOID);
else
return NULL;
}
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 553cc25eb9d..5fdb7e32ce4 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -1450,9 +1450,7 @@ json_object(PG_FUNCTION_ARGS)
errmsg("wrong number of array subscripts")));
}
- deconstruct_array(in_array,
- TEXTOID, -1, false, TYPALIGN_INT,
- &in_datums, &in_nulls, &in_count);
+ deconstruct_array_builtin(in_array, TEXTOID, &in_datums, &in_nulls, &in_count);
count = in_count / 2;
@@ -1526,13 +1524,8 @@ json_object_two_arg(PG_FUNCTION_ARGS)
if (nkdims == 0)
PG_RETURN_DATUM(CStringGetTextDatum("{}"));
- deconstruct_array(key_array,
- TEXTOID, -1, false, TYPALIGN_INT,
- &key_datums, &key_nulls, &key_count);
-
- deconstruct_array(val_array,
- TEXTOID, -1, false, TYPALIGN_INT,
- &val_datums, &val_nulls, &val_count);
+ deconstruct_array_builtin(key_array, TEXTOID, &key_datums, &key_nulls, &key_count);
+ deconstruct_array_builtin(val_array, TEXTOID, &val_datums, &val_nulls, &val_count);
if (key_count != val_count)
ereport(ERROR,
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index 39355e242d2..f700c5b4c93 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -1378,9 +1378,7 @@ jsonb_object(PG_FUNCTION_ARGS)
errmsg("wrong number of array subscripts")));
}
- deconstruct_array(in_array,
- TEXTOID, -1, false, TYPALIGN_INT,
- &in_datums, &in_nulls, &in_count);
+ deconstruct_array_builtin(in_array, TEXTOID, &in_datums, &in_nulls, &in_count);
count = in_count / 2;
@@ -1466,13 +1464,8 @@ jsonb_object_two_arg(PG_FUNCTION_ARGS)
if (nkdims == 0)
goto close_object;
- deconstruct_array(key_array,
- TEXTOID, -1, false, TYPALIGN_INT,
- &key_datums, &key_nulls, &key_count);
-
- deconstruct_array(val_array,
- TEXTOID, -1, false, TYPALIGN_INT,
- &val_datums, &val_nulls, &val_count);
+ deconstruct_array_builtin(key_array, TEXTOID, &key_datums, &key_nulls, &key_count);
+ deconstruct_array_builtin(val_array, TEXTOID, &val_datums, &val_nulls, &val_count);
if (key_count != val_count)
ereport(ERROR,
diff --git a/src/backend/utils/adt/jsonb_gin.c b/src/backend/utils/adt/jsonb_gin.c
index 5edf278cdb0..c5325acde4f 100644
--- a/src/backend/utils/adt/jsonb_gin.c
+++ b/src/backend/utils/adt/jsonb_gin.c
@@ -885,9 +885,7 @@ gin_extract_jsonb_query(PG_FUNCTION_ARGS)
int i,
j;
- deconstruct_array(query,
- TEXTOID, -1, false, TYPALIGN_INT,
- &key_datums, &key_nulls, &key_count);
+ deconstruct_array_builtin(query, TEXTOID, &key_datums, &key_nulls, &key_count);
entries = (Datum *) palloc(sizeof(Datum) * key_count);
diff --git a/src/backend/utils/adt/jsonb_op.c b/src/backend/utils/adt/jsonb_op.c
index ed37252e7f8..202367e9964 100644
--- a/src/backend/utils/adt/jsonb_op.c
+++ b/src/backend/utils/adt/jsonb_op.c
@@ -53,8 +53,7 @@ jsonb_exists_any(PG_FUNCTION_ARGS)
bool *key_nulls;
int elem_count;
- deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
- &key_datums, &key_nulls, &elem_count);
+ deconstruct_array_builtin(keys, TEXTOID, &key_datums, &key_nulls, &elem_count);
for (i = 0; i < elem_count; i++)
{
@@ -86,8 +85,7 @@ jsonb_exists_all(PG_FUNCTION_ARGS)
bool *key_nulls;
int elem_count;
- deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
- &key_datums, &key_nulls, &elem_count);
+ deconstruct_array_builtin(keys, TEXTOID, &key_datums, &key_nulls, &elem_count);
for (i = 0; i < elem_count; i++)
{
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index d427bdfbe0d..9819e1a45ce 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -1000,8 +1000,7 @@ get_path_all(FunctionCallInfo fcinfo, bool as_text)
if (array_contains_nulls(path))
PG_RETURN_NULL();
- deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
- &pathtext, &pathnulls, &npath);
+ deconstruct_array_builtin(path, TEXTOID, &pathtext, &pathnulls, &npath);
tpath = palloc(npath * sizeof(char *));
ipath = palloc(npath * sizeof(int));
@@ -1456,8 +1455,7 @@ get_jsonb_path_all(FunctionCallInfo fcinfo, bool as_text)
if (array_contains_nulls(path))
PG_RETURN_NULL();
- deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
- &pathtext, &pathnulls, &npath);
+ deconstruct_array_builtin(path, TEXTOID, &pathtext, &pathnulls, &npath);
res = jsonb_get_element(jb, pathtext, npath, &isnull, as_text);
@@ -4370,8 +4368,7 @@ jsonb_delete_array(PG_FUNCTION_ARGS)
if (JB_ROOT_COUNT(in) == 0)
PG_RETURN_JSONB_P(in);
- deconstruct_array(keys, TEXTOID, -1, false, TYPALIGN_INT,
- &keys_elems, &keys_nulls, &keys_len);
+ deconstruct_array_builtin(keys, TEXTOID, &keys_elems, &keys_nulls, &keys_len);
if (keys_len == 0)
PG_RETURN_JSONB_P(in);
@@ -4523,8 +4520,7 @@ jsonb_set(PG_FUNCTION_ARGS)
if (JB_ROOT_COUNT(in) == 0 && !create)
PG_RETURN_JSONB_P(in);
- deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
- &path_elems, &path_nulls, &path_len);
+ deconstruct_array_builtin(path, TEXTOID, &path_elems, &path_nulls, &path_len);
if (path_len == 0)
PG_RETURN_JSONB_P(in);
@@ -4635,8 +4631,7 @@ jsonb_delete_path(PG_FUNCTION_ARGS)
if (JB_ROOT_COUNT(in) == 0)
PG_RETURN_JSONB_P(in);
- deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
- &path_elems, &path_nulls, &path_len);
+ deconstruct_array_builtin(path, TEXTOID, &path_elems, &path_nulls, &path_len);
if (path_len == 0)
PG_RETURN_JSONB_P(in);
@@ -4681,8 +4676,7 @@ jsonb_insert(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot set path in scalar")));
- deconstruct_array(path, TEXTOID, -1, false, TYPALIGN_INT,
- &path_elems, &path_nulls, &path_len);
+ deconstruct_array_builtin(path, TEXTOID, &path_elems, &path_nulls, &path_len);
if (path_len == 0)
PG_RETURN_JSONB_P(in);
diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c
index 023a004ac89..dedee7af5cb 100644
--- a/src/backend/utils/adt/lockfuncs.c
+++ b/src/backend/utils/adt/lockfuncs.c
@@ -538,10 +538,7 @@ pg_blocking_pids(PG_FUNCTION_ARGS)
/* Assert we didn't overrun arrayelems[] */
Assert(narrayelems <= lockData->nlocks);
- /* Construct array, using hardwired knowledge about int4 type */
- PG_RETURN_ARRAYTYPE_P(construct_array(arrayelems, narrayelems,
- INT4OID,
- sizeof(int32), true, TYPALIGN_INT));
+ PG_RETURN_ARRAYTYPE_P(construct_array_builtin(arrayelems, narrayelems, INT4OID));
}
@@ -579,10 +576,7 @@ pg_safe_snapshot_blocking_pids(PG_FUNCTION_ARGS)
else
blocker_datums = NULL;
- /* Construct array, using hardwired knowledge about int4 type */
- PG_RETURN_ARRAYTYPE_P(construct_array(blocker_datums, num_blockers,
- INT4OID,
- sizeof(int32), true, TYPALIGN_INT));
+ PG_RETURN_ARRAYTYPE_P(construct_array_builtin(blocker_datums, num_blockers, INT4OID));
}
diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c
index e8bba3670cb..d22e1f277b4 100644
--- a/src/backend/utils/adt/name.c
+++ b/src/backend/utils/adt/name.c
@@ -314,11 +314,7 @@ current_schemas(PG_FUNCTION_ARGS)
}
list_free(search_path);
- array = construct_array(names, i,
- NAMEOID,
- NAMEDATALEN, /* sizeof(Name) */
- false, /* Name is not by-val */
- TYPALIGN_CHAR); /* alignment of Name */
+ array = construct_array_builtin(names, i, NAMEOID);
PG_RETURN_POINTER(array);
}
diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c
index 6d4f6b7dca2..185b2cb8487 100644
--- a/src/backend/utils/adt/orderedsetaggs.c
+++ b/src/backend/utils/adt/orderedsetaggs.c
@@ -759,12 +759,10 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
param = PG_GETARG_ARRAYTYPE_P(1);
- deconstruct_array(param, FLOAT8OID,
- /* hard-wired info on type float8 */
- sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE,
- &percentiles_datum,
- &percentiles_null,
- &num_percentiles);
+ deconstruct_array_builtin(param, FLOAT8OID,
+ &percentiles_datum,
+ &percentiles_null,
+ &num_percentiles);
if (num_percentiles == 0)
PG_RETURN_POINTER(construct_empty_array(osastate->qstate->sortColType));
@@ -883,12 +881,10 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo,
PG_RETURN_NULL();
param = PG_GETARG_ARRAYTYPE_P(1);
- deconstruct_array(param, FLOAT8OID,
- /* hard-wired info on type float8 */
- sizeof(float8), FLOAT8PASSBYVAL, TYPALIGN_DOUBLE,
- &percentiles_datum,
- &percentiles_null,
- &num_percentiles);
+ deconstruct_array_builtin(param, FLOAT8OID,
+ &percentiles_datum,
+ &percentiles_null,
+ &num_percentiles);
if (num_percentiles == 0)
PG_RETURN_POINTER(construct_empty_array(osastate->qstate->sortColType));
diff --git a/src/backend/utils/adt/pg_upgrade_support.c b/src/backend/utils/adt/pg_upgrade_support.c
index 67b9675e92a..65764d78a3d 100644
--- a/src/backend/utils/adt/pg_upgrade_support.c
+++ b/src/backend/utils/adt/pg_upgrade_support.c
@@ -214,9 +214,7 @@ binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
int ndatums;
int i;
- deconstruct_array(textArray,
- TEXTOID, -1, false, TYPALIGN_INT,
- &textDatums, NULL, &ndatums);
+ deconstruct_array_builtin(textArray, TEXTOID, &textDatums, NULL, &ndatums);
for (i = 0; i < ndatums; i++)
{
char *extName = TextDatumGetCString(textDatums[i]);
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index c3937a60fd3..26cf4fa9a0e 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2406,9 +2406,8 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
if (isnull)
elog(ERROR, "null indkey for index %u", indexId);
- deconstruct_array(DatumGetArrayTypeP(cols),
- INT2OID, 2, true, TYPALIGN_SHORT,
- &keys, NULL, &nKeys);
+ deconstruct_array_builtin(DatumGetArrayTypeP(cols), INT2OID,
+ &keys, NULL, &nKeys);
for (j = keyatts; j < nKeys; j++)
{
@@ -2531,9 +2530,8 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
elog(ERROR, "null conexclop for constraint %u",
constraintId);
- deconstruct_array(DatumGetArrayTypeP(val),
- OIDOID, sizeof(Oid), true, TYPALIGN_INT,
- &elems, NULL, &nElems);
+ deconstruct_array_builtin(DatumGetArrayTypeP(val), OIDOID,
+ &elems, NULL, &nElems);
operators = (Oid *) palloc(nElems * sizeof(Oid));
for (i = 0; i < nElems; i++)
@@ -2587,9 +2585,8 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
int j;
/* Extract data from array of int16 */
- deconstruct_array(DatumGetArrayTypeP(column_index_array),
- INT2OID, 2, true, TYPALIGN_SHORT,
- &keys, NULL, &nKeys);
+ deconstruct_array_builtin(DatumGetArrayTypeP(column_index_array), INT2OID,
+ &keys, NULL, &nKeys);
for (j = 0; j < nKeys; j++)
{
@@ -12752,9 +12749,8 @@ get_reloptions(StringInfo buf, Datum reloptions)
int noptions;
int i;
- deconstruct_array(DatumGetArrayTypeP(reloptions),
- TEXTOID, -1, false, TYPALIGN_INT,
- &options, NULL, &noptions);
+ deconstruct_array_builtin(DatumGetArrayTypeP(reloptions), TEXTOID,
+ &options, NULL, &noptions);
for (i = 0; i < noptions; i++)
{
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c
index addc3491518..1786c18f895 100644
--- a/src/backend/utils/adt/tsvector_op.c
+++ b/src/backend/utils/adt/tsvector_op.c
@@ -308,8 +308,7 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS)
memcpy(tsout, tsin, VARSIZE(tsin));
entry = ARRPTR(tsout);
- deconstruct_array(lexemes, TEXTOID, -1, false, TYPALIGN_INT,
- &dlexemes, &nulls, &nlexemes);
+ deconstruct_array_builtin(lexemes, TEXTOID, &dlexemes, &nulls, &nlexemes);
/*
* Assuming that lexemes array is significantly shorter than tsvector we
@@ -586,8 +585,7 @@ tsvector_delete_arr(PG_FUNCTION_ARGS)
Datum *dlexemes;
bool *nulls;
- deconstruct_array(lexemes, TEXTOID, -1, false, TYPALIGN_INT,
- &dlexemes, &nulls, &nlex);
+ deconstruct_array_builtin(lexemes, TEXTOID, &dlexemes, &nulls, &nlex);
/*
* In typical use case array of lexemes to delete is relatively small. So
@@ -694,10 +692,8 @@ tsvector_unnest(PG_FUNCTION_ARGS)
1));
}
- values[1] = PointerGetDatum(construct_array(positions, posv->npos,
- INT2OID, 2, true, TYPALIGN_SHORT));
- values[2] = PointerGetDatum(construct_array(weights, posv->npos,
- TEXTOID, -1, false, TYPALIGN_INT));
+ values[1] = PointerGetDatum(construct_array_builtin(positions, posv->npos, INT2OID));
+ values[2] = PointerGetDatum(construct_array_builtin(weights, posv->npos, TEXTOID));
}
else
{
@@ -733,7 +729,7 @@ tsvector_to_array(PG_FUNCTION_ARGS)
arrin[i].len));
}
- array = construct_array(elements, tsin->size, TEXTOID, -1, false, TYPALIGN_INT);
+ array = construct_array_builtin(elements, tsin->size, TEXTOID);
pfree(elements);
PG_FREE_IF_COPY(tsin, 0);
@@ -757,7 +753,7 @@ array_to_tsvector(PG_FUNCTION_ARGS)
datalen = 0;
char *cur;
- deconstruct_array(v, TEXTOID, -1, false, TYPALIGN_INT, &dlexemes, &nulls, &nitems);
+ deconstruct_array_builtin(v, TEXTOID, &dlexemes, &nulls, &nitems);
/*
* Reject nulls and zero length strings (maybe we should just ignore them,
@@ -833,8 +829,7 @@ tsvector_filter(PG_FUNCTION_ARGS)
int cur_pos = 0;
char mask = 0;
- deconstruct_array(weights, CHAROID, 1, true, TYPALIGN_CHAR,
- &dweights, &nulls, &nweights);
+ deconstruct_array_builtin(weights, CHAROID, &dweights, &nulls, &nweights);
for (i = 0; i < nweights; i++)
{
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 1ec6f1c2fd9..60a85c46971 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -4017,9 +4017,9 @@ xpath_internal(text *xpath_expr_text, xmltype *data, ArrayType *namespaces,
Assert(ARR_ELEMTYPE(namespaces) == TEXTOID);
- deconstruct_array(namespaces, TEXTOID, -1, false, TYPALIGN_INT,
- &ns_names_uris, &ns_names_uris_nulls,
- &ns_count);
+ deconstruct_array_builtin(namespaces, TEXTOID,
+ &ns_names_uris, &ns_names_uris_nulls,
+ &ns_count);
Assert((ns_count % 2) == 0); /* checked above */
ns_count /= 2; /* count pairs only */
diff --git a/src/backend/utils/cache/evtcache.c b/src/backend/utils/cache/evtcache.c
index 3a9c9f0c50e..f7f7165f7fa 100644
--- a/src/backend/utils/cache/evtcache.c
+++ b/src/backend/utils/cache/evtcache.c
@@ -228,8 +228,7 @@ DecodeTextArrayToBitmapset(Datum array)
if (ARR_NDIM(arr) != 1 || ARR_HASNULL(arr) || ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "expected 1-D text array");
- deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
- &elems, NULL, &nelems);
+ deconstruct_array_builtin(arr, TEXTOID, &elems, NULL, &nelems);
for (bms = NULL, i = 0; i < nelems; ++i)
{
diff --git a/src/backend/utils/fmgr/funcapi.c b/src/backend/utils/fmgr/funcapi.c
index 9197b0f1e26..a1fe50ffca8 100644
--- a/src/backend/utils/fmgr/funcapi.c
+++ b/src/backend/utils/fmgr/funcapi.c
@@ -1390,9 +1390,8 @@ get_func_arg_info(HeapTuple procTup,
*p_argnames = NULL;
else
{
- deconstruct_array(DatumGetArrayTypeP(proargnames),
- TEXTOID, -1, false, TYPALIGN_INT,
- &elems, NULL, &nelems);
+ deconstruct_array_builtin(DatumGetArrayTypeP(proargnames), TEXTOID,
+ &elems, NULL, &nelems);
if (nelems != numargs) /* should not happen */
elog(ERROR, "proargnames must have the same number of elements as the function has arguments");
*p_argnames = (char **) palloc(sizeof(char *) * numargs);
@@ -1506,8 +1505,7 @@ get_func_input_arg_names(Datum proargnames, Datum proargmodes,
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array or it contains nulls");
- deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
- &argnames, NULL, &numargs);
+ deconstruct_array_builtin(arr, TEXTOID, &argnames, NULL, &numargs);
if (proargmodes != PointerGetDatum(NULL))
{
arr = DatumGetArrayTypeP(proargmodes); /* ensure not toasted */
@@ -1621,8 +1619,7 @@ get_func_result_name(Oid functionId)
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array of length %d or it contains nulls",
numargs);
- deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
- &argnames, NULL, &nargnames);
+ deconstruct_array_builtin(arr, TEXTOID, &argnames, NULL, &nargnames);
Assert(nargnames == numargs);
/* scan for output argument(s) */
@@ -1770,8 +1767,7 @@ build_function_result_tupdesc_d(char prokind,
ARR_ELEMTYPE(arr) != TEXTOID)
elog(ERROR, "proargnames is not a 1-D text array of length %d or it contains nulls",
numargs);
- deconstruct_array(arr, TEXTOID, -1, false, TYPALIGN_INT,
- &argnames, NULL, &nargnames);
+ deconstruct_array_builtin(arr, TEXTOID, &argnames, NULL, &nargnames);
Assert(nargnames == numargs);
}
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index a7cc49898b0..f640468f113 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -9974,7 +9974,7 @@ pg_settings_get_flags(PG_FUNCTION_ARGS)
Assert(cnt <= MAX_GUC_FLAGS);
/* Returns the record as Datum */
- a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
+ a = construct_array_builtin(flags, cnt, TEXTOID);
PG_RETURN_ARRAYTYPE_P(a);
}
@@ -11507,9 +11507,7 @@ GUCArrayAdd(ArrayType *array, const char *name, const char *value)
TYPALIGN_INT /* TEXT's typalign */ );
}
else
- a = construct_array(&datum, 1,
- TEXTOID,
- -1, false, TYPALIGN_INT);
+ a = construct_array_builtin(&datum, 1, TEXTOID);
return a;
}
@@ -11576,9 +11574,7 @@ GUCArrayDelete(ArrayType *array, const char *name)
false /* TEXT's typbyval */ ,
TYPALIGN_INT /* TEXT's typalign */ );
else
- newarray = construct_array(&d, 1,
- TEXTOID,
- -1, false, TYPALIGN_INT);
+ newarray = construct_array_builtin(&d, 1, TEXTOID);
index++;
}
@@ -11644,9 +11640,7 @@ GUCArrayReset(ArrayType *array)
false /* TEXT's typbyval */ ,
TYPALIGN_INT /* TEXT's typalign */ );
else
- newarray = construct_array(&d, 1,
- TEXTOID,
- -1, false, TYPALIGN_INT);
+ newarray = construct_array_builtin(&d, 1, TEXTOID);
index++;
pfree(val);