This is an automated email from the ASF dual-hosted git repository.
paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git
The following commit(s) were added to refs/heads/main by this push:
new 6494471 fix: Improve readability of `ArrowArrayAllocateChildren()`
(#199)
6494471 is described below
commit 64944714534d488593ee930d383eb5581fb440fe
Author: Dirk Eddelbuettel <[email protected]>
AuthorDate: Sun May 21 21:22:43 2023 -0500
fix: Improve readability of `ArrowArrayAllocateChildren()` (#199)
In `ArrowArrayAllocateChildren()` two loops over all children follow
each other directly. The first assigns a NULL to each element, then
second overwrites that with an allocation. That makes the first loop
effectively deadweight. It may be there on purpose in which case you
just disregard and close this PR. But if it is an oversight this will
make it ever-so-marginally faster as we can skip one loop over
`n_children`.
(I noticed another microscopic style difference: in the corresponding
`ArrowSchemaAllocateChildren()` an `if (n_children != 0) {...}` wraps
around the core code of function; there it is a simpler `if (n_children
== 0) return ...`. Of course they are also the same "in practice" and I
don't have a style preference either -- just curious that they differ.
No need for change, but while at it you could....)
---------
Co-authored-by: Dewey Dunnington <[email protected]>
---
src/nanoarrow/array.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/nanoarrow/array.c b/src/nanoarrow/array.c
index cd6a639..ec321e6 100644
--- a/src/nanoarrow/array.c
+++ b/src/nanoarrow/array.c
@@ -228,9 +228,7 @@ ArrowErrorCode ArrowArrayAllocateChildren(struct
ArrowArray* array, int64_t n_ch
return ENOMEM;
}
- for (int64_t i = 0; i < n_children; i++) {
- array->children[i] = NULL;
- }
+ memset(array->children, 0, n_children * sizeof(struct ArrowArray*));
for (int64_t i = 0; i < n_children; i++) {
array->children[i] = (struct ArrowArray*)ArrowMalloc(sizeof(struct
ArrowArray));