perf: do not use TotalVoices as it causes heap allocations

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-11-02 20:44:45 +02:00
parent b73fc0b95b
commit 943073d0cc
2 changed files with 10 additions and 2 deletions

View File

@ -422,7 +422,11 @@ func (p Patch) FirstVoiceForInstrument(instrIndex int) int {
return 0
}
instrIndex = min(instrIndex, len(p))
return TotalVoices(p[:instrIndex])
ret := 0
for i := 0; i < instrIndex; i++ {
ret += p[i].NumVoices
}
return ret
}
// InstrumentForVoice returns the instrument number for the given voice index.

View File

@ -275,7 +275,11 @@ func (l Score) FirstVoiceForTrack(track int) int {
return 0
}
track = min(track, len(l.Tracks))
return TotalVoices(l.Tracks[:track])
ret := 0
for i := 0; i < track; i++ {
ret += l.Tracks[i].NumVoices
}
return ret
}
// LengthInRows returns just RowsPerPattern * Length, as the length is the