networkusage: avoid intermediate array copy for history updates
This commit is contained in:
parent
11b30a0f69
commit
ce7fe96097
1 changed files with 4 additions and 12 deletions
|
|
@ -192,21 +192,13 @@ Singleton {
|
||||||
const maxHistory = root.historyLength + 1;
|
const maxHistory = root.historyLength + 1;
|
||||||
|
|
||||||
if (root._downloadSpeed >= 0 && isFinite(root._downloadSpeed)) {
|
if (root._downloadSpeed >= 0 && isFinite(root._downloadSpeed)) {
|
||||||
let newDownHist = root._downloadHistory.slice();
|
const dh = root._downloadHistory;
|
||||||
newDownHist.push(root._downloadSpeed);
|
root._downloadHistory = dh.length >= maxHistory ? [...dh.slice(1), root._downloadSpeed] : [...dh, root._downloadSpeed];
|
||||||
if (newDownHist.length > maxHistory) {
|
|
||||||
newDownHist.shift();
|
|
||||||
}
|
|
||||||
root._downloadHistory = newDownHist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root._uploadSpeed >= 0 && isFinite(root._uploadSpeed)) {
|
if (root._uploadSpeed >= 0 && isFinite(root._uploadSpeed)) {
|
||||||
let newUpHist = root._uploadHistory.slice();
|
const uh = root._uploadHistory;
|
||||||
newUpHist.push(root._uploadSpeed);
|
root._uploadHistory = uh.length >= maxHistory ? [...uh.slice(1), root._uploadSpeed] : [...uh, root._uploadSpeed];
|
||||||
if (newUpHist.length > maxHistory) {
|
|
||||||
newUpHist.shift();
|
|
||||||
}
|
|
||||||
root._uploadHistory = newUpHist;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue