@@ -795,19 +795,29 @@ function copy(source, destination, stackSource, stackDest) {
795
795
796
796
if ( ! destination ) {
797
797
destination = source ;
798
- if ( source ) {
798
+ if ( isObject ( source ) ) {
799
+ var index ;
800
+ if ( stackSource && ( index = stackSource . indexOf ( source ) ) !== - 1 ) {
801
+ return stackDest [ index ] ;
802
+ }
803
+
799
804
if ( isArray ( source ) ) {
800
- destination = copy ( source , [ ] , stackSource , stackDest ) ;
805
+ return copy ( source , [ ] , stackSource , stackDest ) ;
801
806
} else if ( isTypedArray ( source ) ) {
802
807
destination = new source . constructor ( source ) ;
803
808
} else if ( isDate ( source ) ) {
804
809
destination = new Date ( source . getTime ( ) ) ;
805
810
} else if ( isRegExp ( source ) ) {
806
811
destination = new RegExp ( source . source , source . toString ( ) . match ( / [ ^ \/ ] * $ / ) [ 0 ] ) ;
807
812
destination . lastIndex = source . lastIndex ;
808
- } else if ( isObject ( source ) ) {
813
+ } else {
809
814
var emptyObject = Object . create ( getPrototypeOf ( source ) ) ;
810
- destination = copy ( source , emptyObject , stackSource , stackDest ) ;
815
+ return copy ( source , emptyObject , stackSource , stackDest ) ;
816
+ }
817
+
818
+ if ( stackDest ) {
819
+ stackSource . push ( source ) ;
820
+ stackDest . push ( destination ) ;
811
821
}
812
822
}
813
823
} else {
@@ -818,9 +828,6 @@ function copy(source, destination, stackSource, stackDest) {
818
828
stackDest = stackDest || [ ] ;
819
829
820
830
if ( isObject ( source ) ) {
821
- var index = stackSource . indexOf ( source ) ;
822
- if ( index !== - 1 ) return stackDest [ index ] ;
823
-
824
831
stackSource . push ( source ) ;
825
832
stackDest . push ( destination ) ;
826
833
}
@@ -829,12 +836,7 @@ function copy(source, destination, stackSource, stackDest) {
829
836
if ( isArray ( source ) ) {
830
837
destination . length = 0 ;
831
838
for ( var i = 0 ; i < source . length ; i ++ ) {
832
- result = copy ( source [ i ] , null , stackSource , stackDest ) ;
833
- if ( isObject ( source [ i ] ) ) {
834
- stackSource . push ( source [ i ] ) ;
835
- stackDest . push ( result ) ;
836
- }
837
- destination . push ( result ) ;
839
+ destination . push ( copy ( source [ i ] , null , stackSource , stackDest ) ) ;
838
840
}
839
841
} else {
840
842
var h = destination . $$hashKey ;
@@ -848,37 +850,27 @@ function copy(source, destination, stackSource, stackDest) {
848
850
if ( isBlankObject ( source ) ) {
849
851
// createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
850
852
for ( key in source ) {
851
- putValue ( key , source [ key ] , destination , stackSource , stackDest ) ;
853
+ destination [ key ] = copy ( source [ key ] , null , stackSource , stackDest ) ;
852
854
}
853
855
} else if ( source && typeof source . hasOwnProperty === 'function' ) {
854
856
// Slow path, which must rely on hasOwnProperty
855
857
for ( key in source ) {
856
858
if ( source . hasOwnProperty ( key ) ) {
857
- putValue ( key , source [ key ] , destination , stackSource , stackDest ) ;
859
+ destination [ key ] = copy ( source [ key ] , null , stackSource , stackDest ) ;
858
860
}
859
861
}
860
862
} else {
861
863
// Slowest path --- hasOwnProperty can't be called as a method
862
864
for ( key in source ) {
863
865
if ( hasOwnProperty . call ( source , key ) ) {
864
- putValue ( key , source [ key ] , destination , stackSource , stackDest ) ;
866
+ destination [ key ] = copy ( source [ key ] , null , stackSource , stackDest ) ;
865
867
}
866
868
}
867
869
}
868
870
setHashKey ( destination , h ) ;
869
871
}
870
872
}
871
873
return destination ;
872
-
873
- function putValue ( key , val , destination , stackSource , stackDest ) {
874
- // No context allocation, trivial outer scope, easily inlined
875
- var result = copy ( val , null , stackSource , stackDest ) ;
876
- if ( isObject ( val ) ) {
877
- stackSource . push ( val ) ;
878
- stackDest . push ( result ) ;
879
- }
880
- destination [ key ] = result ;
881
- }
882
874
}
883
875
884
876
/**
0 commit comments