* array_contains_nulls --- detect whether an array has any null elements * * This gives an accurate answer, whereas testing ARR_HASNULL only tells * if the array *might* contain a null. */
| 3655 | * if the array *might* contain a null. |
| 3656 | */ |
| 3657 | bool |
| 3658 | array_contains_nulls(ArrayType *array) |
| 3659 | { |
| 3660 | int nelems; |
| 3661 | bits8 *bitmap; |
| 3662 | int bitmask; |
| 3663 | |
| 3664 | /* Easy answer if there's no null bitmap */ |
| 3665 | if (!ARR_HASNULL(array)) |
| 3666 | return false; |
| 3667 | |
| 3668 | nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array)); |
| 3669 | |
| 3670 | bitmap = ARR_NULLBITMAP(array); |
| 3671 | |
| 3672 | /* check whole bytes of the bitmap byte-at-a-time */ |
| 3673 | while (nelems >= 8) |
| 3674 | { |
| 3675 | if (*bitmap != 0xFF) |
| 3676 | return true; |
| 3677 | bitmap++; |
| 3678 | nelems -= 8; |
| 3679 | } |
| 3680 | |
| 3681 | /* check last partial byte */ |
| 3682 | bitmask = 1; |
| 3683 | while (nelems > 0) |
| 3684 | { |
| 3685 | if ((*bitmap & bitmask) == 0) |
| 3686 | return true; |
| 3687 | bitmask <<= 1; |
| 3688 | nelems--; |
| 3689 | } |
| 3690 | |
| 3691 | return false; |
| 3692 | } |
| 3693 | |
| 3694 | |
| 3695 | /* |
no test coverage detected