diff --git a/android/app/src/main/java/com/clhs/score/ui/SubjectTrendLineChart.kt b/android/app/src/main/java/com/clhs/score/ui/SubjectTrendLineChart.kt index ccbe1b8..0614b4c 100644 --- a/android/app/src/main/java/com/clhs/score/ui/SubjectTrendLineChart.kt +++ b/android/app/src/main/java/com/clhs/score/ui/SubjectTrendLineChart.kt @@ -113,13 +113,12 @@ fun SubjectTrendLineChart( val dashedLines = mutableMapOf, Triple, Color>>>() groupedSubjects.forEach { (baseName, keys) -> - val allPoints = mutableListOf>() - keys.forEach { key -> - subjectPoints[key]?.forEachIndexed { index, score -> - if (score != null) { - allPoints.add(Triple(index, score, key)) - } - } + // Optimization: Replace manual mutable list initialization and nested iteration + // with a single flatMap step to improve parsing performance and reduce memory allocations + val allPoints = keys.flatMap { key -> + subjectPoints[key]?.mapIndexedNotNull { index, score -> + if (score != null) Triple(index, score, key) else null + } ?: emptyList() } allPointsMap[baseName] = allPoints