hapijs / hoek

Node utilities shared among the extended hapi universe
Other
480 stars 171 forks source link

Safer and faster shallow handling #343

Closed kanongil closed 4 years ago

kanongil commented 4 years ago

This patch refactors the shallow handling of clone() and applyToDefaults() to avoid temporarily modifying the source object, and setting properties on the target object multiple times.

The handling is done in a simple and effective manner by pre-filling a seen Map() that is passed to the internal call to clone().

This new handling should also increase the performance of shallow copies.

hueniverse commented 4 years ago

Smart.

The clone() change is a breaking change because if a value is used by more than one key, and you only shallow one, the other one will now also be shallow. This is fine for all my use cases but it is a breaking change.

I need to review the applyToDefaults() change more closely.