Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript
https://turfjs.org/
MIT License
9.3k stars 941 forks source link

New module `@turf/clone` #780

Closed DenisCarriere closed 7 years ago

DenisCarriere commented 7 years ago

New module proposal @turf/clone

Noticed when we want to prevent input mutation we typically do the following:

geojson = JSON.parse(JSON.stringify(geojson));

However, most of the times we only need to clone the coordinates since that's the only thing that might be mutated.

Using coordinates.slice() vs. the JSON parse & stringify combo is about 8x times faster which can increase the performance of a "mutating" module/operation from 50,000 ops/sec to 400,000 ops/sec.

Expected Example

var clone = require('@turf/clone');
geojson = clone(geojson);

Ref: https://developers.google.com/web/updates/2017/06/object-rest-spread

DenisCarriere commented 7 years ago

Being implemented via PR https://github.com/Turfjs/turf/pull/824