From b6633b4c519a0aa579ed9c0653fa78fe99f6487b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 20 Nov 2020 01:56:19 +0100 Subject: [PATCH] Fix circular array. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 6 +++--- package.json | 2 +- src/utils/CircularArray.ts | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2cb919f3..064f931c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10647,9 +10647,9 @@ } }, "typescript": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.5.tgz", - "integrity": "sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz", + "integrity": "sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==", "dev": true }, "ultron": { diff --git a/package.json b/package.json index c4ade427..67b3d25f 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,6 @@ "npm-check": "^5.9.2", "rimraf": "^3.0.2", "ts-node-dev": "^1.0.0", - "typescript": "^4.0.5" + "typescript": "^4.1.2" } } diff --git a/src/utils/CircularArray.ts b/src/utils/CircularArray.ts index 5dab1e2c..434a8f49 100644 --- a/src/utils/CircularArray.ts +++ b/src/utils/CircularArray.ts @@ -9,15 +9,15 @@ export default class CircularArray extends Array { } push(...items: T[]): number { - while (this.length > this.size) { - this.shift(); + if (this.length + items.length > this.size) { + super.splice(0, (this.length + items.length) - this.size); } return super.push(...items); } unshift(...items: T[]): number { - while (this.length > this.size) { - this.pop(); + if (this.length + items.length > this.size) { + super.splice(this.size - items.length, (this.length + items.length) - this.size); } return super.unshift(...items); } -- 2.34.1