mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Use wrappers of PG_DETOAST_DATUM_PACKED() more.
This makes almost all core code follow the policy introduced in the previous commit. Specific decisions: - Text search support functions with char* and length arguments, such as prsstart and lexize, may receive unaligned strings. I doubt maintainers of non-core text search code will notice. - Use plain VARDATA() on values detoasted or synthesized earlier in the same function. Use VARDATA_ANY() on varlenas sourced outside the function, even if they happen to always have four-byte headers. As an exception, retain the universal practice of using VARDATA() on return values of SendFunctionCall(). - Retain PG_GETARG_BYTEA_P() in pageinspect. (Page images are too large for a one-byte header, so this misses no optimization.) Sites that do not call get_page_from_raw() typically need the four-byte alignment. - For now, do not change btree_gist. Its use of four-byte headers in memory is partly entangled with storage of 4-byte headers inside GBT_VARKEY, on disk. - For now, do not change gtrgm_consistent() or gtrgm_distance(). They incorporate the varlena header into a cache, and there are multiple credible implementation strategies to consider.
This commit is contained in:
@ -2662,7 +2662,7 @@ bytea_catenate(bytea *t1, bytea *t2)
|
||||
}
|
||||
|
||||
#define PG_STR_GET_BYTEA(str_) \
|
||||
DatumGetByteaP(DirectFunctionCall1(byteain, CStringGetDatum(str_)))
|
||||
DatumGetByteaPP(DirectFunctionCall1(byteain, CStringGetDatum(str_)))
|
||||
|
||||
/*
|
||||
* bytea_substr()
|
||||
@ -2934,13 +2934,12 @@ byteaGetBit(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
byteaSetByte(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *v = PG_GETARG_BYTEA_P(0);
|
||||
bytea *res = PG_GETARG_BYTEA_P_COPY(0);
|
||||
int32 n = PG_GETARG_INT32(1);
|
||||
int32 newByte = PG_GETARG_INT32(2);
|
||||
int len;
|
||||
bytea *res;
|
||||
|
||||
len = VARSIZE(v) - VARHDRSZ;
|
||||
len = VARSIZE(res) - VARHDRSZ;
|
||||
|
||||
if (n < 0 || n >= len)
|
||||
ereport(ERROR,
|
||||
@ -2948,12 +2947,6 @@ byteaSetByte(PG_FUNCTION_ARGS)
|
||||
errmsg("index %d out of valid range, 0..%d",
|
||||
n, len - 1)));
|
||||
|
||||
/*
|
||||
* Make a copy of the original varlena.
|
||||
*/
|
||||
res = (bytea *) palloc(VARSIZE(v));
|
||||
memcpy((char *) res, (char *) v, VARSIZE(v));
|
||||
|
||||
/*
|
||||
* Now set the byte.
|
||||
*/
|
||||
@ -2973,17 +2966,16 @@ byteaSetByte(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
byteaSetBit(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *v = PG_GETARG_BYTEA_P(0);
|
||||
bytea *res = PG_GETARG_BYTEA_P_COPY(0);
|
||||
int32 n = PG_GETARG_INT32(1);
|
||||
int32 newBit = PG_GETARG_INT32(2);
|
||||
bytea *res;
|
||||
int len;
|
||||
int oldByte,
|
||||
newByte;
|
||||
int byteNo,
|
||||
bitNo;
|
||||
|
||||
len = VARSIZE(v) - VARHDRSZ;
|
||||
len = VARSIZE(res) - VARHDRSZ;
|
||||
|
||||
if (n < 0 || n >= len * 8)
|
||||
ereport(ERROR,
|
||||
@ -3002,12 +2994,6 @@ byteaSetBit(PG_FUNCTION_ARGS)
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("new bit must be 0 or 1")));
|
||||
|
||||
/*
|
||||
* Make a copy of the original varlena.
|
||||
*/
|
||||
res = (bytea *) palloc(VARSIZE(v));
|
||||
memcpy((char *) res, (char *) v, VARSIZE(v));
|
||||
|
||||
/*
|
||||
* Update the byte.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user