Fix: Avoid eager List allocation in countDiffLineStats for large diffs
Replaced `diff.split("\n")` with `diff.lineSequence()` in `FileRenderers.kt`'s `countDiffLineStats()` method. This prevents massive `ArrayList` allocations on the heap when processing multi-thousand-line diffs during tool card rendering, improving memory efficiency by evaluating the lines lazily.
Added comprehensive unit tests in `FileEditSupportTest.kt` covering empty diffs, header filtering, CRLF handling, and large multi-line diffs.
This commit is contained in:
1 parent
f520cf2dce
commit
304a90186a
2 files changed
+55
-1
No files matched your search
@@ -79,7 +79,7 @@ internal object FileEditSupport {
|
||||
var added = 0
|
||||
var removed = 0
|
||||
|
||||
for (line in diff.split("\n")) {
|
||||
for (line in diff.lineSequence()) {
|
||||
when {
|
||||
line.startsWith("+") && !line.startsWith("+++") -> added += 1
|
||||
line.startsWith("-") && !line.startsWith("---") -> removed += 1
|
||||
|
||||
Reference in new issue
Block a user