* Extract a slice of an array into consecutive elements in the destination * array. * * We assume the caller has verified that the slice coordinates are valid, * allocated enough storage for the result, and initialized the header * of the new array. */
| 4984 | * of the new array. |
| 4985 | */ |
| 4986 | static void |
| 4987 | array_extract_slice(ArrayType *newarray, |
| 4988 | int ndim, |
| 4989 | int *dim, |
| 4990 | int *lb, |
| 4991 | char *arraydataptr, |
| 4992 | bits8 *arraynullsptr, |
| 4993 | int *st, |
| 4994 | int *endp, |
| 4995 | int typlen, |
| 4996 | bool typbyval, |
| 4997 | char typalign) |
| 4998 | { |
| 4999 | char *destdataptr = ARR_DATA_PTR(newarray); |
| 5000 | bits8 *destnullsptr = ARR_NULLBITMAP(newarray); |
| 5001 | char *srcdataptr; |
| 5002 | int src_offset, |
| 5003 | dest_offset, |
| 5004 | prod[MAXDIM], |
| 5005 | span[MAXDIM], |
| 5006 | dist[MAXDIM], |
| 5007 | indx[MAXDIM]; |
| 5008 | int i, |
| 5009 | j, |
| 5010 | inc; |
| 5011 | |
| 5012 | src_offset = ArrayGetOffset(ndim, dim, lb, st); |
| 5013 | srcdataptr = array_seek(arraydataptr, 0, arraynullsptr, src_offset, |
| 5014 | typlen, typbyval, typalign); |
| 5015 | mda_get_prod(ndim, dim, prod); |
| 5016 | mda_get_range(ndim, span, st, endp); |
| 5017 | mda_get_offset_values(ndim, dist, prod, span); |
| 5018 | for (i = 0; i < ndim; i++) |
| 5019 | indx[i] = 0; |
| 5020 | dest_offset = 0; |
| 5021 | j = ndim - 1; |
| 5022 | do |
| 5023 | { |
| 5024 | if (dist[j]) |
| 5025 | { |
| 5026 | /* skip unwanted elements */ |
| 5027 | srcdataptr = array_seek(srcdataptr, src_offset, arraynullsptr, |
| 5028 | dist[j], |
| 5029 | typlen, typbyval, typalign); |
| 5030 | src_offset += dist[j]; |
| 5031 | } |
| 5032 | inc = array_copy(destdataptr, 1, |
| 5033 | srcdataptr, src_offset, arraynullsptr, |
| 5034 | typlen, typbyval, typalign); |
| 5035 | if (destnullsptr) |
| 5036 | array_bitmap_copy(destnullsptr, dest_offset, |
| 5037 | arraynullsptr, src_offset, |
| 5038 | 1); |
| 5039 | destdataptr += inc; |
| 5040 | srcdataptr += inc; |
| 5041 | src_offset++; |
| 5042 | dest_offset++; |
| 5043 | } while ((j = mda_next_tuple(ndim, indx, span)) != -1); |
no test coverage detected