| 39 | |
| 40 | template <typename VALUE, typename APPEND_FUNCTION> |
| 41 | gboolean |
| 42 | garrow_array_builder_append_values(VALUE *values, |
| 43 | gint64 values_length, |
| 44 | const gboolean *is_valids, |
| 45 | gint64 is_valids_length, |
| 46 | GError **error, |
| 47 | const gchar *context, |
| 48 | APPEND_FUNCTION append_function) |
| 49 | { |
| 50 | if (is_valids_length > 0) { |
| 51 | if (values_length != is_valids_length) { |
| 52 | g_set_error(error, |
| 53 | GARROW_ERROR, |
| 54 | GARROW_ERROR_INVALID, |
| 55 | "%s: values length and is_valids length must be equal: " |
| 56 | "<%" G_GINT64_FORMAT "> != " |
| 57 | "<%" G_GINT64_FORMAT ">", |
| 58 | context, |
| 59 | values_length, |
| 60 | is_valids_length); |
| 61 | return FALSE; |
| 62 | } |
| 63 | |
| 64 | const gint64 chunk_size = 4096; |
| 65 | gint64 n_chunks = is_valids_length / chunk_size; |
| 66 | gint64 n_remains = is_valids_length % chunk_size; |
| 67 | gint64 n_loops = n_chunks; |
| 68 | if (n_remains > 0) { |
| 69 | ++n_loops; |
| 70 | } |
| 71 | for (gint64 i = 0; i < n_loops; ++i) { |
| 72 | uint8_t valid_bytes[chunk_size]; |
| 73 | gint64 offset = chunk_size * i; |
| 74 | const gboolean *chunked_is_valids = is_valids + offset; |
| 75 | gint64 n_values; |
| 76 | if (i == n_chunks) { |
| 77 | n_values = n_remains; |
| 78 | } else { |
| 79 | n_values = chunk_size; |
| 80 | } |
| 81 | for (gint64 j = 0; j < n_values; ++j) { |
| 82 | valid_bytes[j] = chunked_is_valids[j]; |
| 83 | } |
| 84 | auto status = append_function(values + offset, n_values, valid_bytes); |
| 85 | if (!garrow_error_check(error, status, context)) { |
| 86 | return FALSE; |
| 87 | } |
| 88 | } |
| 89 | return TRUE; |
| 90 | } else { |
| 91 | auto status = append_function(values, values_length, nullptr); |
| 92 | return garrow_error_check(error, status, context); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | template <typename BUILDER, typename VALUE> |
| 97 | gboolean |
no test coverage detected