* initArrayResultWithSize * As initArrayResult, but allow the initial size of the allocated arrays * to be specified. */
| 5198 | * to be specified. |
| 5199 | */ |
| 5200 | ArrayBuildState * |
| 5201 | initArrayResultWithSize(Oid element_type, MemoryContext rcontext, bool subcontext, int initsize) |
| 5202 | { |
| 5203 | ArrayBuildState *astate; |
| 5204 | MemoryContext arr_context = rcontext; |
| 5205 | |
| 5206 | /* Make a temporary context to hold all the junk */ |
| 5207 | if (subcontext) |
| 5208 | arr_context = AllocSetContextCreate(rcontext, |
| 5209 | "accumArrayResult", |
| 5210 | ALLOCSET_DEFAULT_SIZES); |
| 5211 | |
| 5212 | astate = (ArrayBuildState *) |
| 5213 | MemoryContextAlloc(arr_context, sizeof(ArrayBuildState)); |
| 5214 | astate->mcontext = arr_context; |
| 5215 | astate->private_cxt = subcontext; |
| 5216 | astate->alen = initsize; |
| 5217 | astate->dvalues = (Datum *) |
| 5218 | MemoryContextAlloc(arr_context, astate->alen * sizeof(Datum)); |
| 5219 | astate->dnulls = (bool *) |
| 5220 | MemoryContextAlloc(arr_context, astate->alen * sizeof(bool)); |
| 5221 | astate->nelems = 0; |
| 5222 | astate->element_type = element_type; |
| 5223 | get_typlenbyvalalign(element_type, |
| 5224 | &astate->typlen, |
| 5225 | &astate->typbyval, |
| 5226 | &astate->typalign); |
| 5227 | |
| 5228 | return astate; |
| 5229 | } |
| 5230 | |
| 5231 | /* |
| 5232 | * accumArrayResult - accumulate one (more) Datum for an array result |
no test coverage detected