Преглед на файлове

Merge pull request #742 from herby/use-anysatisfy

replace 'detect:ifNone: ~=' hacks with anySatisfy:
Nicolas Petton преди 10 години
родител
ревизия
102b904104
променени са 4 файла, в които са добавени 17 реда и са изтрити 28 реда
  1. 4 7
      js/Compiler-AST.js
  2. 6 12
      js/Kernel-Collections.js
  3. 6 6
      st/Compiler-AST.st
  4. 1 3
      st/Kernel-Collections.st

+ 4 - 7
js/Compiler-AST.js

@@ -630,20 +630,17 @@ return smalltalk.withContext(function($ctx2) {
 return self._shouldBeInlined();
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})})))._or_((function(){
 return smalltalk.withContext(function($ctx2) {
-return _st(_st(self._nodes())._detect_ifNone_((function(each){
+return _st(self._nodes())._anySatisfy_((function(each){
 return smalltalk.withContext(function($ctx3) {
 return _st(each)._subtreeNeedsAliasing();
-}, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2,3)})}),(function(){
-return smalltalk.withContext(function($ctx3) {
-return false;
-}, function($ctx3) {$ctx3.fillBlock({},$ctx2,4)})}))).__tild_eq(false);
+}, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2,3)})}));
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
 $ctx1.sendIdx["or:"]=1;
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"subtreeNeedsAliasing",{},smalltalk.Node)})},
 args: [],
-source: "subtreeNeedsAliasing\x0a\x09^ (self shouldBeAliased or: [ self shouldBeInlined ]) or: [\x0a\x09\x09(self nodes detect: [ :each | each subtreeNeedsAliasing ] ifNone: [ false ]) ~= false ]",
-messageSends: ["or:", "shouldBeAliased", "shouldBeInlined", "~=", "detect:ifNone:", "nodes", "subtreeNeedsAliasing"],
+source: "subtreeNeedsAliasing\x0a\x09^ (self shouldBeAliased or: [ self shouldBeInlined ]) or: [\x0a\x09\x09self nodes anySatisfy: [ :each | each subtreeNeedsAliasing ] ]",
+messageSends: ["or:", "shouldBeAliased", "shouldBeInlined", "anySatisfy:", "nodes", "subtreeNeedsAliasing"],
 referencedClasses: []
 }),
 smalltalk.Node);

+ 6 - 12
js/Kernel-Collections.js

@@ -658,24 +658,18 @@ selector: "includes:",
 category: 'testing',
 fn: function (anObject){
 var self=this;
-var sentinel;
-function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-sentinel=_st($Object())._new();
-$1=_st(self._detect_ifNone_((function(each){
+$1=self._anySatisfy_((function(each){
 return smalltalk.withContext(function($ctx2) {
 return _st(each).__eq(anObject);
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}),(function(){
-return smalltalk.withContext(function($ctx2) {
-return sentinel;
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}))).__tild_eq(sentinel);
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
 return $1;
-}, function($ctx1) {$ctx1.fill(self,"includes:",{anObject:anObject,sentinel:sentinel},smalltalk.Collection)})},
+}, function($ctx1) {$ctx1.fill(self,"includes:",{anObject:anObject},smalltalk.Collection)})},
 args: ["anObject"],
-source: "includes: anObject\x0a\x09| sentinel |\x0a\x09sentinel := Object new.\x0a\x09^ (self detect: [ :each | each = anObject ] ifNone: [ sentinel ]) ~= sentinel",
-messageSends: ["new", "~=", "detect:ifNone:", "="],
-referencedClasses: ["Object"]
+source: "includes: anObject\x0a\x09^ self anySatisfy: [ :each | each = anObject ]",
+messageSends: ["anySatisfy:", "="],
+referencedClasses: []
 }),
 smalltalk.Collection);
 

+ 6 - 6
st/Compiler-AST.st

@@ -48,7 +48,7 @@ nextNode: aNode
 !
 
 nodes
-	^ nodes ifNil: [ nodes := Array new ] 
+	^ nodes ifNil: [ nodes := Array new ]
 !
 
 parent
@@ -168,7 +168,7 @@ stopOnStepping
 
 subtreeNeedsAliasing
 	^ (self shouldBeAliased or: [ self shouldBeInlined ]) or: [
-		(self nodes detect: [ :each | each subtreeNeedsAliasing ] ifNone: [ false ]) ~= false ]
+		self nodes anySatisfy: [ :each | each subtreeNeedsAliasing ] ]
 ! !
 
 !Node methodsFor: 'visiting'!
@@ -244,7 +244,7 @@ nextNode: aNode
 !
 
 parameters
-	^ parameters ifNil: [ parameters := Array new ] 
+	^ parameters ifNil: [ parameters := Array new ]
 !
 
 parameters: aCollection
@@ -336,7 +336,7 @@ I represent an JavaScript statement node.!
 !JSStatementNode methodsFor: 'accessing'!
 
 source
-	^ source ifNil: [ '' ] 
+	^ source ifNil: [ '' ]
 !
 
 source: aString
@@ -366,7 +366,7 @@ A method node must be the root and only method node of a valid AST.!
 !MethodNode methodsFor: 'accessing'!
 
 arguments
-	^ arguments ifNil: [ #() ] 
+	^ arguments ifNil: [ #() ]
 !
 
 arguments: aCollection
@@ -480,7 +480,7 @@ I represent an message send node.!
 !SendNode methodsFor: 'accessing'!
 
 arguments
-	^ arguments ifNil: [ arguments := #() ] 
+	^ arguments ifNil: [ arguments := #() ]
 !
 
 arguments: aCollection

+ 1 - 3
st/Kernel-Collections.st

@@ -299,9 +299,7 @@ ifNotEmpty: aBlock ifEmpty: anotherBlock
 !
 
 includes: anObject
-	| sentinel |
-	sentinel := Object new.
-	^ (self detect: [ :each | each = anObject ] ifNone: [ sentinel ]) ~= sentinel
+	^ self anySatisfy: [ :each | each = anObject ]
 !
 
 isEmpty