jsedding commented on code in PR #3149:
URL: https://github.com/apache/jackrabbit-oak/pull/3149#discussion_r4106066198
##########
oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/DefaultSegmentWriter.java:
##########
@@ -452,12 +451,15 @@ private RecordId writeList(@NotNull List<RecordId> list)
throws IOException {
checkArgument(!list.isEmpty());
List<RecordId> thisLevel = list;
while (thisLevel.size() > 1) {
- List<RecordId> nextLevel = new ArrayList<>();
- for (List<RecordId> bucket :
ListUtils.partitionList(thisLevel, ListRecord.LEVEL_SIZE)) {
- if (bucket.size() > 1) {
- nextLevel.add(writeListBucket(bucket));
+ int size = thisLevel.size();
+ int levelSize = ListRecord.LEVEL_SIZE;
+ List<RecordId> nextLevel = new ArrayList<>((size + levelSize -
1) / levelSize);
Review Comment:
The math here is a little obscure 🙂
IIUC you are relying on integer division doing the "rounding", and you add
254 to the `size` in order to get the "ceiling" of the division. Unless I am
mistaken, this is equivalent to `Math.toIntExact(Math.round(Math.ceil((double)
size / levelSize)))`, right? Your code is likely more performant, so I think
you should keep it as-is.
Maybe add a short comment to clarify?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]