* Compute space needed for a slice of an array * * We assume the caller has verified that the slice coordinates are valid. */
| 4924 | * We assume the caller has verified that the slice coordinates are valid. |
| 4925 | */ |
| 4926 | static int |
| 4927 | array_slice_size(char *arraydataptr, bits8 *arraynullsptr, |
| 4928 | int ndim, int *dim, int *lb, |
| 4929 | int *st, int *endp, |
| 4930 | int typlen, bool typbyval, char typalign) |
| 4931 | { |
| 4932 | int src_offset, |
| 4933 | span[MAXDIM], |
| 4934 | prod[MAXDIM], |
| 4935 | dist[MAXDIM], |
| 4936 | indx[MAXDIM]; |
| 4937 | char *ptr; |
| 4938 | int i, |
| 4939 | j, |
| 4940 | inc; |
| 4941 | int count = 0; |
| 4942 | |
| 4943 | mda_get_range(ndim, span, st, endp); |
| 4944 | |
| 4945 | /* Pretty easy for fixed element length without nulls ... */ |
| 4946 | if (typlen > 0 && !arraynullsptr) |
| 4947 | return ArrayGetNItems(ndim, span) * att_align_nominal(typlen, typalign); |
| 4948 | |
| 4949 | /* Else gotta do it the hard way */ |
| 4950 | src_offset = ArrayGetOffset(ndim, dim, lb, st); |
| 4951 | ptr = array_seek(arraydataptr, 0, arraynullsptr, src_offset, |
| 4952 | typlen, typbyval, typalign); |
| 4953 | mda_get_prod(ndim, dim, prod); |
| 4954 | mda_get_offset_values(ndim, dist, prod, span); |
| 4955 | for (i = 0; i < ndim; i++) |
| 4956 | indx[i] = 0; |
| 4957 | j = ndim - 1; |
| 4958 | do |
| 4959 | { |
| 4960 | if (dist[j]) |
| 4961 | { |
| 4962 | ptr = array_seek(ptr, src_offset, arraynullsptr, dist[j], |
| 4963 | typlen, typbyval, typalign); |
| 4964 | src_offset += dist[j]; |
| 4965 | } |
| 4966 | if (!array_get_isnull(arraynullsptr, src_offset)) |
| 4967 | { |
| 4968 | inc = att_addlength_pointer(0, typlen, ptr); |
| 4969 | inc = att_align_nominal(inc, typalign); |
| 4970 | ptr += inc; |
| 4971 | count += inc; |
| 4972 | } |
| 4973 | src_offset++; |
| 4974 | } while ((j = mda_next_tuple(ndim, indx, span)) != -1); |
| 4975 | return count; |
| 4976 | } |
| 4977 | |
| 4978 | /* |
| 4979 | * Extract a slice of an array into consecutive elements in the destination |
no test coverage detected