diff --git a/src/Containers-KeyedTree-Tests/CTKeyedTreeTest.class.st b/src/Containers-KeyedTree-Tests/CTKeyedTreeTest.class.st index 55aac9f..f3fd7ee 100644 --- a/src/Containers-KeyedTree-Tests/CTKeyedTreeTest.class.st +++ b/src/Containers-KeyedTree-Tests/CTKeyedTreeTest.class.st @@ -215,6 +215,25 @@ CTKeyedTreeTest >> testCopy [ self assert: (c includesKey: #new) ] +{ #category : 'tests' } +CTKeyedTreeTest >> testDeepCopyStateNotShared [ + | original clone | + original := CTKeyedTree new + at: #config put: (CTKeyedTree new + at: #color put: 'red'; + yourself); + yourself. + + clone := original copy. + + (clone at: #config) at: #color put: 'blue'. + + self assert: (original atPath: #(config color)) equals: 'red'. + self assert: (clone atPath: #(config color)) equals: 'blue'. + + self deny: (original at: #config) == (clone at: #config). +] + { #category : 'tests' } CTKeyedTreeTest >> testDepth [ diff --git a/src/Containers-KeyedTree/CTKeyedTree.class.st b/src/Containers-KeyedTree/CTKeyedTree.class.st index 38cb423..d5959be 100644 --- a/src/Containers-KeyedTree/CTKeyedTree.class.st +++ b/src/Containers-KeyedTree/CTKeyedTree.class.st @@ -268,21 +268,6 @@ CTKeyedTree >> collect: aBlock [ ^ result ] -{ #category : 'copying' } -CTKeyedTree >> copy [ - - "Answer a deep copy of the receiver including all subtrees." - - | result | - result := self species new. - self keysAndValuesDo: [ :key :value | - result at: key put: ( - (value isKindOf: self class) - ifTrue: [ value copy ] - ifFalse: [ value ] ) ]. - ^ result -] - { #category : 'accessing' } CTKeyedTree >> depth [ @@ -496,16 +481,11 @@ CTKeyedTree >> pathsAndValuesDo: aBlock currentPath: pathArray [ { #category : 'copying' } CTKeyedTree >> postCopy [ - - "Ensure proper deep copying of associations and subtrees." - array := array collect: [ :assoc | - assoc ifNotNil: [ - Association - key: assoc key - value: ((assoc value isKindOf: self class) - ifTrue: [ assoc value copy ] - ifFalse: [ assoc value ]) ] ] + super postCopy. + self keysAndValuesDo: [ :key :value | + (value isKindOf: self class) + ifTrue: [ self at: key put: value copy ] ] ] { #category : 'printing' }