Skip to content

Commit 962cdfc

Browse files
committed
[SQL] Minor: Avoid calling Seq#size in a loop
Just found this instance while doing some jstack-based profiling of a Spark SQL job. It is very unlikely that this is causing much of a perf regression anywhere, but it is unnecessarily suboptimal.
1 parent 96b2785 commit 962cdfc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullFunctions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ case class Coalesce(children: Seq[Expression]) extends Expression {
4545
override def eval(input: Row): Any = {
4646
var i = 0
4747
var result: Any = null
48-
while(i < children.size && result == null) {
49-
result = children(i).eval(input)
50-
i += 1
48+
val childIterator = children.iterator
49+
while (childIterator.hasNext && result == null) {
50+
result = childIterator.next().eval(input)
5151
}
5252
result
5353
}

0 commit comments

Comments
 (0)