@@ -201,19 +201,21 @@ exports.cloneWithShallow = function (source, keys) {
201
201
202
202
const storage = internals . store ( source , keys ) ; // Move shallow copy items to storage
203
203
const copy = exports . clone ( source ) ; // Deep copy the rest
204
- internals . restore ( copy , source , storage ) ; // Shallow copy the stored items and restore
204
+ internals . restore ( copy , source , storage ) ; // Shallow copy the stored items and restore
205
205
return copy ;
206
206
} ;
207
207
208
208
209
209
internals . store = function ( source , keys ) {
210
210
211
- const storage = { } ;
211
+ const storage = new Map ( ) ;
212
212
for ( let i = 0 ; i < keys . length ; ++ i ) {
213
213
const key = keys [ i ] ;
214
214
const value = exports . reach ( source , key ) ;
215
- if ( value !== undefined ) {
216
- storage [ key ] = value ;
215
+ if ( typeof value === 'object' ||
216
+ typeof value === 'function' ) {
217
+
218
+ storage . set ( key , value ) ;
217
219
internals . reachSet ( source , key , undefined ) ;
218
220
}
219
221
}
@@ -224,18 +226,16 @@ internals.store = function (source, keys) {
224
226
225
227
internals . restore = function ( copy , source , storage ) {
226
228
227
- const keys = Object . keys ( storage ) ;
228
- for ( let i = 0 ; i < keys . length ; ++ i ) {
229
- const key = keys [ i ] ;
230
- internals . reachSet ( copy , key , storage [ key ] ) ;
231
- internals . reachSet ( source , key , storage [ key ] ) ;
229
+ for ( const [ key , value ] of storage ) {
230
+ internals . reachSet ( copy , key , value ) ;
231
+ internals . reachSet ( source , key , value ) ;
232
232
}
233
233
} ;
234
234
235
235
236
236
internals . reachSet = function ( obj , key , value ) {
237
237
238
- const path = key . split ( '.' ) ;
238
+ const path = Array . isArray ( key ) ? key : key . split ( '.' ) ;
239
239
let ref = obj ;
240
240
for ( let i = 0 ; i < path . length ; ++ i ) {
241
241
const segment = path [ i ] ;
0 commit comments