diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 22:22:50 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2026-03-12 22:22:50 +1100 |
| commit | ce7fe9609721d63ab37ff8ae18d94346b18e5f7f (patch) | |
| tree | 790a44b02874e024eb5158c88ab3b00581b94df9 /services/NetworkUsage.qml | |
| parent | strings: cache compiled RegExp objects (diff) | |
| download | caelestia-shell-ce7fe9609721d63ab37ff8ae18d94346b18e5f7f.tar.gz caelestia-shell-ce7fe9609721d63ab37ff8ae18d94346b18e5f7f.tar.bz2 caelestia-shell-ce7fe9609721d63ab37ff8ae18d94346b18e5f7f.zip | |
networkusage: avoid intermediate array copy for history updates
Diffstat (limited to 'services/NetworkUsage.qml')
| -rw-r--r-- | services/NetworkUsage.qml | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/services/NetworkUsage.qml b/services/NetworkUsage.qml index 502ec3a..a940648 100644 --- a/services/NetworkUsage.qml +++ b/services/NetworkUsage.qml @@ -192,21 +192,13 @@ Singleton { const maxHistory = root.historyLength + 1; if (root._downloadSpeed >= 0 && isFinite(root._downloadSpeed)) { - let newDownHist = root._downloadHistory.slice(); - newDownHist.push(root._downloadSpeed); - if (newDownHist.length > maxHistory) { - newDownHist.shift(); - } - root._downloadHistory = newDownHist; + const dh = root._downloadHistory; + root._downloadHistory = dh.length >= maxHistory ? [...dh.slice(1), root._downloadSpeed] : [...dh, root._downloadSpeed]; } if (root._uploadSpeed >= 0 && isFinite(root._uploadSpeed)) { - let newUpHist = root._uploadHistory.slice(); - newUpHist.push(root._uploadSpeed); - if (newUpHist.length > maxHistory) { - newUpHist.shift(); - } - root._uploadHistory = newUpHist; + const uh = root._uploadHistory; + root._uploadHistory = uh.length >= maxHistory ? [...uh.slice(1), root._uploadSpeed] : [...uh, root._uploadSpeed]; } } |