Skip to content

Commit

Permalink
optimize(Path2D): replace reassign-concat with for-push (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu committed Feb 24, 2021
1 parent 413c861 commit 315d56b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions __tests__/classes/Path2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});

});
3 changes: 2 additions & 1 deletion src/classes/Path2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

0 comments on commit 315d56b

Please sign in to comment.