Browse Source

Fixed issue #92 with Dictionary>>deepCopy

Nicolas Petton 12 years ago
parent
commit
500faeb742
3 changed files with 41 additions and 0 deletions
  1. 14 0
      js/Kernel.deploy.js
  2. 19 0
      js/Kernel.js
  3. 8 0
      st/Kernel.st

+ 14 - 0
js/Kernel.deploy.js

@@ -5208,6 +5208,20 @@ return self;}
 }),
 smalltalk.Dictionary);
 
+smalltalk.addMethod(
+'_deepCopy',
+smalltalk.method({
+selector: 'deepCopy',
+fn: function (){
+var self=this;
+var copy=nil;
+copy=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
+smalltalk.send(self, "_associationsDo_", [(function(each){return smalltalk.send(copy, "_at_put_", [smalltalk.send(each, "_key", []), smalltalk.send(smalltalk.send(each, "_value", []), "_deepCopy", [])]);})]);
+return copy;
+return self;}
+}),
+smalltalk.Dictionary);
+
 
 smalltalk.addMethod(
 '_fromPairs_',

+ 19 - 0
js/Kernel.js

@@ -7420,6 +7420,25 @@ referencedClasses: []
 }),
 smalltalk.Dictionary);
 
+smalltalk.addMethod(
+unescape('_deepCopy'),
+smalltalk.method({
+selector: unescape('deepCopy'),
+category: 'copying',
+fn: function (){
+var self=this;
+var copy=nil;
+copy=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
+smalltalk.send(self, "_associationsDo_", [(function(each){return smalltalk.send(copy, "_at_put_", [smalltalk.send(each, "_key", []), smalltalk.send(smalltalk.send(each, "_value", []), "_deepCopy", [])]);})]);
+return copy;
+return self;},
+args: [],
+source: unescape('deepCopy%0A%09%7C%20copy%20%7C%0A%09copy%20%3A%3D%20self%20class%20new.%0A%09self%20associationsDo%3A%20%5B%3Aeach%20%7C%0A%09%20%20%20%20copy%20at%3A%20each%20key%20%20put%3A%20each%20value%20deepCopy%5D.%0A%09%5Ecopy'),
+messageSends: ["new", "class", "associationsDo:", "at:put:", "key", "deepCopy", "value"],
+referencedClasses: []
+}),
+smalltalk.Dictionary);
+
 
 smalltalk.addMethod(
 unescape('_fromPairs_'),

+ 8 - 0
st/Kernel.st

@@ -2525,6 +2525,14 @@ shallowCopy
 
 copyFrom: anIndex to: anotherIndex
 	self shouldNotImplement
+!
+
+deepCopy
+	| copy |
+	copy := self class new.
+	self associationsDo: [:each |
+	    copy at: each key  put: each value deepCopy].
+	^copy
 ! !
 
 !Dictionary methodsFor: 'enumerating'!