Skip to content

Commit 9d4b092

Browse files
committed
chore: simplify path clone logic
1 parent 749c00d commit 9d4b092

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

intersect.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ function hasProperty(obj, property) {
2929
return Object.prototype.hasOwnProperty.call(obj, property);
3030
}
3131

32-
function clone(obj) {
33-
34-
if (typeof obj == 'function' || Object(obj) !== obj) {
35-
return obj;
36-
}
37-
38-
var res = new obj.constructor;
39-
40-
for (var key in obj) {
41-
if (hasProperty(obj, key)) {
42-
res[key] = clone(obj[key]);
43-
}
44-
}
45-
46-
return res;
47-
}
48-
4932
function repush(array, item) {
5033
for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
5134
return array.push(array.splice(i, 1)[0]);
@@ -184,9 +167,21 @@ function pathToString() {
184167
* @return {PathComponent[]}
185168
*/
186169
function pathClone(pathComponents) {
187-
var res = clone(pathComponents);
188-
res.toString = pathToString;
189-
return res;
170+
171+
var pathComponentsClone = new Array(pathComponents.length);
172+
173+
for (var i = 0, ii = pathComponents.length; i < ii; i++) {
174+
var component = pathComponents[i];
175+
var componentClone = pathComponentsClone[i] = new Array(component.length);
176+
177+
for (var j = 0, jj = component.length; j < jj; j++) {
178+
componentClone[j] = component[j];
179+
}
180+
}
181+
182+
pathComponentsClone.toString = pathToString;
183+
184+
return pathComponentsClone;
190185
}
191186

192187
function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {

0 commit comments

Comments
 (0)