uros-b opened a new pull request, #57883:
URL: https://github.com/apache/spark/pull/57883
### What changes were proposed in this pull request?
Uses the idiomatic emptiness checks for the three `ArrayBuffer` length
comparisons in `ExternalAppendOnlyMap`:
```scala
if (kcPairs.nonEmpty) { // was kcPairs.length > 0
def isEmpty: Boolean = pairs.isEmpty // was pairs.length == 0
assert(pairs.nonEmpty) // was assert(pairs.length > 0)
```
### Why are the changes needed?
The same file already uses this form for its other emptiness checks
(`spilledMaps.isEmpty`, `mergeHeap.nonEmpty`, `mergeHeap.isEmpty`), as does the
sibling `ExternalSorter`, so these three were the odd ones out.
To be clear about scope: this is a **readability change, not a performance
optimization**. For `ArrayBuffer` both forms are O(1) and exactly equivalent --
`isEmpty` resolves to `SeqOps.isEmpty`, which is `lengthCompare(0) == 0` over
the buffer's cached size -- so there is no measurable difference either way.
The `currentMap.size > 0` check in `forceSpill` is deliberately **not**
changed. `AppendOnlyMap` is an `Iterable` rather than a `Seq` and does not
override `knownSize`, so `isEmpty` there would fall through to `iterator()`,
which asserts the map has not been destructively sorted. Since `forceSpill` can
run under memory pressure after `destructiveSortedIterator` has been called,
that site must stay a size comparison.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Behavior-preserving, so the existing `ExternalAppendOnlyMapSuite` coverage
applies, in particular the spill and hash-collision tests that drive
`StreamBuffer` with more than one pair per hash. The three predicates have
identical truth values for every possible buffer state, so no branch can be
taken differently.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]