[MINOR][CORE] Simplify the next-page index computation in BytesToBytesMap.MapIterator - #58736
Open
david-mollitor-db wants to merge 1 commit into
Open
[MINOR][CORE] Simplify the next-page index computation in BytesToBytesMap.MapIterator#58736david-mollitor-db wants to merge 1 commit into
david-mollitor-db wants to merge 1 commit into
Conversation
…sMap.MapIterator
`MapIterator.advanceToNextPage()` computed the next page index as
`int nextIdx = dataPages.indexOf(currentPage) + 1;` and then decremented it inside a
conditional (`nextIdx--`). Reuse the `indexOf` result and set `nextIdx` once in an
`if`/`else` so it can be `final`:
final int idx = dataPages.indexOf(currentPage);
final int nextIdx;
if (destructive && idx >= 0) {
dataPages.remove(idx);
pageToFree = currentPage;
nextIdx = idx;
} else {
nextIdx = idx + 1;
}
`idx >= 0` is equivalent to the previous `currentPage != null` guard (whenever
`currentPage` is non-null it is an element of `dataPages`, and `indexOf(null)` is `-1`),
and reusing `idx` for `remove(idx)` avoids the redundant second linear scan that
`remove(Object)` performs. Behavior is unchanged. No lock or I/O behavior is changed.
Generated-by: Claude Opus 4.8
Co-authored-by: Isaac <no-reply@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
MapIterator.advanceToNextPage()inBytesToBytesMapcomputed the next-page index asint nextIdx = dataPages.indexOf(currentPage) + 1;and then decremented it (nextIdx--) inside aconditional. This reuses the
indexOfresult and setsnextIdxonce in anif/elseso it can befinal:Why are the changes needed?
Minor readability/consistency cleanup:
nextIdxbecomesfinaland is assigned exactly once perbranch instead of being mutated.
idx >= 0is equivalent to the previouscurrentPage != nullguard — whenever
currentPageis non-null it is an element ofdataPages(assigned fromdataPages.get(...)and only removed here), andindexOf(null)is-1. Reusingidxforremove(idx)also avoids the redundant second linear scan thatremove(Object)performs. No lock orI/O behavior is changed.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing
BytesToBytesMapOnHeapSuiteandBytesToBytesMapOffHeapSuitepass (34 tests, coveringdestructive iteration, spill, reset, and free); checkstyle is clean.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.8
This pull request and its description were written by Isaac.