diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-07-01 10:51:45 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-07-01 11:23:15 +0200 |
commit | d746021de18baf0f29eff0388204a0664f41eb8b (patch) | |
tree | 21074e7935e62cd054e702d79e5c1fe7c8544733 /src/backend/utils/adt/tsvector_op.c | |
parent | 7c2d6f8d3400edab2b91de7765db9ec71235fac9 (diff) | |
download | postgresql-d746021de18baf0f29eff0388204a0664f41eb8b.tar.gz postgresql-d746021de18baf0f29eff0388204a0664f41eb8b.zip |
Add construct_array_builtin, deconstruct_array_builtin
There were many calls to construct_array() and deconstruct_array() for
built-in types, for example, when dealing with system catalog columns.
These all hardcoded the type attributes necessary to pass to these
functions.
To simplify this a bit, add construct_array_builtin(),
deconstruct_array_builtin() as wrappers that centralize this hardcoded
knowledge. This simplifies many call sites and reduces the amount of
hardcoded stuff that is spread around.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/2914356f-9e5f-8c59-2995-5997fc48bcba%40enterprisedb.com
Diffstat (limited to 'src/backend/utils/adt/tsvector_op.c')
-rw-r--r-- | src/backend/utils/adt/tsvector_op.c | 19 |
1 files changed, 7 insertions, 12 deletions
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++) { |