File tree Expand file tree Collapse file tree
android/app/src/main/java/com/clhs/score/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -135,10 +135,14 @@ fun SubjectTrendLineChart(
135135 val currentPoints = pointsByIndex[indices[i]]!!
136136 val nextPoints = pointsByIndex[indices[i+ 1 ]]!!
137137
138+ // Optimization: Precompute subjects to avoid O(N^3) complexity
139+ val currentSubjects = currentPoints.map { it.third }.toSet()
140+ val nextSubjects = nextPoints.map { it.third }.toSet()
141+
138142 currentPoints.forEach { p1 ->
139143 nextPoints.forEach { p2 ->
140- val p1HasSuccessor = nextPoints.any { it.third == p1.third }
141- val p2HasPredecessor = currentPoints.any { it.third == p2.third }
144+ val p1HasSuccessor = nextSubjects.contains( p1.third)
145+ val p2HasPredecessor = currentSubjects.contains( p2.third)
142146
143147 val isDifferentSubjectConnection = (! p1HasSuccessor || ! p2HasPredecessor) && p1.third != p2.third
144148 val isSameSubjectGap = p1.third == p2.third && (p2.first - p1.first > 1 )
You can’t perform that action at this time.
0 commit comments