1
0
Kaynağa Gözat

Fixes issue #356

Nicolas Petton 12 yıl önce
ebeveyn
işleme
f376c51649

+ 20 - 5
js/Kernel-Collections.deploy.js

@@ -3324,11 +3324,26 @@ smalltalk.method({
 selector: "=",
 fn: function (aCollection) {
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
var $1;
-$1=_st(_st(_st(self)._class()).__eq(_st(aCollection)._class()))._and_((function(){
-return smalltalk.withContext(function($ctx2) {
return _st(_st(self)._asArray()).__eq(_st(aCollection)._asArray());
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
-return $1;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3;
+var $early={};
+try {
+$1=_st(_st(self)._class()).__eq(_st(aCollection)._class());
+if(! smalltalk.assert($1)){
+return false;
+};
+$2=_st(_st(self)._size()).__eq(_st(aCollection)._size());
+if(! smalltalk.assert($2)){
+return false;
+};
+_st(self)._do_((function(each){
+return smalltalk.withContext(function($ctx2) {
$3=_st(aCollection)._includes_(each);
+if(! smalltalk.assert($3)){
+throw $early=[false];
+};
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
+return true;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
 }, function($ctx1) {$ctx1.fill(self,"=",{aCollection:aCollection}, smalltalk.Set)});}
 }),
 smalltalk.Set);

+ 22 - 7
js/Kernel-Collections.js

@@ -4486,15 +4486,30 @@ selector: "=",
 category: 'comparing',
 fn: function (aCollection) {
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
var $1;
-$1=_st(_st(_st(self)._class()).__eq(_st(aCollection)._class()))._and_((function(){
-return smalltalk.withContext(function($ctx2) {
return _st(_st(self)._asArray()).__eq(_st(aCollection)._asArray());
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
-return $1;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3;
+var $early={};
+try {
+$1=_st(_st(self)._class()).__eq(_st(aCollection)._class());
+if(! smalltalk.assert($1)){
+return false;
+};
+$2=_st(_st(self)._size()).__eq(_st(aCollection)._size());
+if(! smalltalk.assert($2)){
+return false;
+};
+_st(self)._do_((function(each){
+return smalltalk.withContext(function($ctx2) {
$3=_st(aCollection)._includes_(each);
+if(! smalltalk.assert($3)){
+throw $early=[false];
+};
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
+return true;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
 }, function($ctx1) {$ctx1.fill(self,"=",{aCollection:aCollection}, smalltalk.Set)});},
 args: ["aCollection"],
-source: "= aCollection\x0a\x09^self class = aCollection class and: [\x0a\x09\x09self asArray = aCollection asArray]",
-messageSends: ["and:", "=", "asArray", "class"],
+source: "= aCollection\x0a\x09self class = aCollection class ifFalse: [ ^ false ].\x0a    self size = aCollection size ifFalse: [ ^ false ].\x0a\x09self do: [:each | (aCollection includes: each) ifFalse: [ ^ false ] ].\x0a\x09^ true",
+messageSends: ["ifFalse:", "=", "class", "size", "do:", "includes:"],
 referencedClasses: []
 }),
 smalltalk.Set);

+ 1 - 0
js/Kernel-Tests.deploy.js

@@ -2901,6 +2901,7 @@ selector: "testComparing",
 fn: function () {
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
_st(self)._assert_equals_(_st([(0), (2)])._asSet(),_st([(0), (2)])._asSet());
+_st(self)._assert_equals_(_st([(2), (0)])._asSet(),_st([(0), (2)])._asSet());
 _st(self)._deny_(_st(_st([(0), (2), (3)])._asSet()).__eq(_st([(0), (2)])._asSet()));
 _st(self)._deny_(_st(_st([(1), (2)])._asSet()).__eq(_st([(0), (2)])._asSet()));
 return self}, function($ctx1) {$ctx1.fill(self,"testComparing",{}, smalltalk.SetTest)});}

+ 2 - 1
js/Kernel-Tests.js

@@ -3738,11 +3738,12 @@ category: 'tests',
 fn: function () {
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
_st(self)._assert_equals_(_st([(0), (2)])._asSet(),_st([(0), (2)])._asSet());
+_st(self)._assert_equals_(_st([(2), (0)])._asSet(),_st([(0), (2)])._asSet());
 _st(self)._deny_(_st(_st([(0), (2), (3)])._asSet()).__eq(_st([(0), (2)])._asSet()));
 _st(self)._deny_(_st(_st([(1), (2)])._asSet()).__eq(_st([(0), (2)])._asSet()));
 return self}, function($ctx1) {$ctx1.fill(self,"testComparing",{}, smalltalk.SetTest)});},
 args: [],
-source: "testComparing\x0a\x09self assert: #(0 2) asSet equals: #(0 2) asSet.\x0a    self deny: #(0 2 3) asSet = #(0 2) asSet.\x0a    self deny: #(1 2) asSet = #(0 2) asSet",
+source: "testComparing\x0a\x09self assert: #(0 2) asSet equals: #(0 2) asSet.\x0a    self assert: #(2 0) asSet equals: #(0 2) asSet.\x0a    self deny: #(0 2 3) asSet = #(0 2) asSet.\x0a    self deny: #(1 2) asSet = #(0 2) asSet",
 messageSends: ["assert:equals:", "asSet", "deny:", "="],
 referencedClasses: []
 }),

+ 4 - 2
st/Kernel-Collections.st

@@ -1445,8 +1445,10 @@ remove: anObject
 !Set methodsFor: 'comparing'!
 
 = aCollection
-	^self class = aCollection class and: [
-		self asArray = aCollection asArray]
+	self class = aCollection class ifFalse: [ ^ false ].
+    self size = aCollection size ifFalse: [ ^ false ].
+	self do: [:each | (aCollection includes: each) ifFalse: [ ^ false ] ].
+	^ true
 ! !
 
 !Set methodsFor: 'converting'!

+ 1 - 0
st/Kernel-Tests.st

@@ -1486,6 +1486,7 @@ testCollect
 
 testComparing
 	self assert: #(0 2) asSet equals: #(0 2) asSet.
+    self assert: #(2 0) asSet equals: #(0 2) asSet.
     self deny: #(0 2 3) asSet = #(0 2) asSet.
     self deny: #(1 2) asSet = #(0 2) asSet
 !