Skip to content

Commit 9149654

Browse files
He-PinCopilot
andcommitted
Optimize Val.Obj.visibleKeyNames: while-loop instead of forEach lambda
Replace getAllKeys.forEach with entrySet iterator while-loop to avoid per-key lambda allocation overhead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8cd8d31 commit 9149654

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sjsonnet/src/sjsonnet/Val.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,11 @@ object Val {
659659
buf.sizeHint(value0.size())
660660
value0.forEach((k, m) => if (m.visibility != Visibility.Hidden) buf += k)
661661
} else {
662-
getAllKeys.forEach((k, b) => if (b == java.lang.Boolean.FALSE) buf += k)
662+
val iter = getAllKeys.entrySet().iterator()
663+
while (iter.hasNext()) {
664+
val e = iter.next()
665+
if (e.getValue() == java.lang.Boolean.FALSE) buf += e.getKey()
666+
}
663667
}
664668
buf.result()
665669
}

0 commit comments

Comments
 (0)