From 315d56b2dacf292f27fe84b690620957ddeadbdd Mon Sep 17 00:00:00 2001 From: milahu Date: Wed, 24 Feb 2021 09:07:59 +0200 Subject: [PATCH] optimize(Path2D): replace reassign-concat with for-push (#76) --- __tests__/classes/Path2D.js | 15 +++++++++++++++ src/classes/Path2D.js | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/__tests__/classes/Path2D.js b/__tests__/classes/Path2D.js index 71fef0e..95fe505 100644 --- a/__tests__/classes/Path2D.js +++ b/__tests__/classes/Path2D.js @@ -58,4 +58,19 @@ describe('Path2D', () => { mockWindow(window); expect(saved === window.Path2D).toBe(true); }); + + test('Path2D addPath calls _path.push', () => { + const path1 = new Path2D(); + path1.moveTo(10, 10); + path1.lineTo(20, 20); + const path2 = new Path2D(); + path2.moveTo(30, 30); + path2.lineTo(40, 40); + expect(path1._path.length).toBe(2); + path1.addPath(path2); + expect(path1._path.length).toBe(4); + expect(path1._path[2]).toBe(path2._path[0]); + expect(path1._path[3]).toBe(path2._path[1]); + }); + }); diff --git a/src/classes/Path2D.js b/src/classes/Path2D.js index 2d984e8..01dc12d 100644 --- a/src/classes/Path2D.js +++ b/src/classes/Path2D.js @@ -39,6 +39,7 @@ export default class Path2D { throw new TypeError( "Failed to execute 'addPath' on 'Path2D': parameter 1 is not of type 'Path2D'." ); - this._path = this._path.concat(path._path); + for (let i = 0; i < path._path.length; i++) + this._path.push(path._path[i]); } }