Skip to content

Commit a4e46d9

Browse files
⚡ Bolt: [performance improvement] Optimize nested list processing in SubjectTrendLineChart
Co-authored-by: alvin000009238 <107313913+alvin000009238@users.noreply.github.com>
1 parent fd03a1f commit a4e46d9

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

android/app/src/main/java/com/clhs/score/ui/SubjectTrendLineChart.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,12 @@ fun SubjectTrendLineChart(
113113
val dashedLines = mutableMapOf<String, List<Triple<Triple<Int, Double, String>, Triple<Int, Double, String>, Color>>>()
114114

115115
groupedSubjects.forEach { (baseName, keys) ->
116-
val allPoints = mutableListOf<Triple<Int, Double, String>>()
117-
keys.forEach { key ->
118-
subjectPoints[key]?.forEachIndexed { index, score ->
119-
if (score != null) {
120-
allPoints.add(Triple(index, score, key))
121-
}
122-
}
116+
// Optimization: Replace manual mutable list initialization and nested iteration
117+
// with a single flatMap step to improve parsing performance and reduce memory allocations
118+
val allPoints = keys.flatMap { key ->
119+
subjectPoints[key]?.mapIndexedNotNull { index, score ->
120+
if (score != null) Triple(index, score, key) else null
121+
} ?: emptyList()
123122
}
124123
allPointsMap[baseName] = allPoints
125124

0 commit comments

Comments
 (0)