MCPcopy Create free account
hub / github.com/apache/cloudberry / CopyArrayEls

Function CopyArrayEls

src/backend/utils/adt/arrayfuncs.c:963–1011  ·  view source on GitHub ↗

* Copy data into an array object from a temporary array of Datums. * * array: array object (with header fields already filled in) * values: array of Datums to be copied * nulls: array of is-null flags (can be NULL if no nulls) * nitems: number of Datums to be copied * typbyval, typlen, typalign: info about element datatype * freedata: if true and element type is pass-by-ref, pfree data valu

Source from the content-addressed store, hash-verified

961 * caller has already allocated space for the array...)
962 */
963void
964CopyArrayEls(ArrayType *array,
965 Datum *values,
966 bool *nulls,
967 int nitems,
968 int typlen,
969 bool typbyval,
970 char typalign,
971 bool freedata)
972{
973 char *p = ARR_DATA_PTR(array);
974 bits8 *bitmap = ARR_NULLBITMAP(array);
975 int bitval = 0;
976 int bitmask = 1;
977 int i;
978
979 if (typbyval)
980 freedata = false;
981
982 for (i = 0; i < nitems; i++)
983 {
984 if (nulls && nulls[i])
985 {
986 if (!bitmap) /* shouldn't happen */
987 elog(ERROR, "null array element where not supported");
988 /* bitmap bit stays 0 */
989 }
990 else
991 {
992 bitval |= bitmask;
993 p += ArrayCastAndSet(values[i], typlen, typbyval, typalign, p);
994 if (freedata)
995 pfree(DatumGetPointer(values[i]));
996 }
997 if (bitmap)
998 {
999 bitmask <<= 1;
1000 if (bitmask == 0x100 /* (1<<8) */)
1001 {
1002 *bitmap++ = bitval;
1003 bitval = 0;
1004 bitmask = 1;
1005 }
1006 }
1007 }
1008
1009 if (bitmap && bitmask != 1)
1010 *bitmap = bitval;
1011}
1012
1013/*
1014 * array_out :

Callers 6

EA_flatten_intoFunction · 0.85
array_inFunction · 0.85
array_recvFunction · 0.85
array_mapFunction · 0.85
construct_md_arrayFunction · 0.85
array_replace_internalFunction · 0.85

Calls 2

ArrayCastAndSetFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected