stefanvodita commented on code in PR #12995: URL: https://github.com/apache/lucene/pull/12995#discussion_r1459792589
########## lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/TaxonomyIndexArrays.java: ########## @@ -68,25 +94,66 @@ public TaxonomyIndexArrays(IndexReader reader, TaxonomyIndexArrays copyFrom) thr // it may be caused if e.g. the taxonomy segments were merged, and so an updated // NRT reader was obtained, even though nothing was changed. this is not very likely // to happen. - int[] copyParents = copyFrom.parents(); - this.parents = new int[reader.maxDoc()]; - System.arraycopy(copyParents, 0, parents, 0, copyParents.length); - initParents(reader, copyParents.length); - + int[][] parentArray = allocateChunkedArray(reader.maxDoc(), copyFrom.parents.values.length - 1); + if (parentArray.length > 0) { + copyChunkedArray(copyFrom.parents.values, parentArray); + initParents(parentArray, reader, copyFrom.parents.length()); + } + parents = new ChunkedIntArray(parentArray); if (copyFrom.initializedChildren) { initChildrenSiblings(copyFrom); } } + private static int[][] allocateChunkedArray(int size, int startFrom) { + if (size == 0) { + return new int[0][]; + } + int chunkCount = size >> CHUNK_SIZE_BITS; + int fullChunkCount; + int lastChunkSize = size & CHUNK_MASK; + if (lastChunkSize == 0) { Review Comment: Thank you for persisting while we're iterating over this method. Since `fullChunkCount` is assigned `chunkCount` on both branches, why not do this: ```java int fullChunkCount = chunkCount; if (lastChunkSize != 0) { chunkCount++; } ``` On a higher level, I think I still wasn't specific enough in my previous comment. I didn't mind that we would sometimes have an empty array at the end if `size` was a multiple of `CHUNK_SIZE`, but we had if-statements that didn't seem to me like they were adding something. In this case, I prefer spending those extra bytes if we can make the code simpler. If you think the implementation we already have is better, we can keep it, but here is my preferred solution written out if you want to consider it: ```java private static int[][] allocateChunkedArray(int size, int startFrom) { int chunkCount = (size >> CHUNK_SIZE_BITS) + 1; int[][] array = new int[chunkCount][]; for (int i = startFrom; i < chunkCount - 1; i++) { array[i] = new int[CHUNK_SIZE]; } array[chunkCount - 1] = new int[size & CHUNK_MASK]; return array; } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org