Browse Source

Optimize some uses of #and:.

Herby Vojčík 4 years ago
parent
commit
01ae5c0265

+ 11 - 17
lang/src/Compiler-AST.js

@@ -2008,31 +2008,25 @@ selector: "superSend",
 protocol: "accessing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "superSend\x0a\x09^ self receiver notNil and: [ self receiver isSuper ]",
+source: "superSend\x0a\x09^ self receiver ifNil: [ false ] ifNotNil: [ :recv | recv isSuper ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["and:", "notNil", "receiver", "isSuper"]
+messageSends: ["ifNil:ifNotNil:", "receiver", "isSuper"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $2,$1;
-$2=$self._receiver();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["receiver"]=1;
-//>>excludeEnd("ctx");
-$1=$recv($2)._notNil();
-return $recv($1)._and_((function(){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-return $recv($self._receiver())._isSuper();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
-//>>excludeEnd("ctx");
-}));
+var $1,$receiver;
+$1=$self._receiver();
+if(($receiver = $1) == null || $receiver.a$nil){
+return false;
+} else {
+var recv;
+recv=$receiver;
+return $recv(recv)._isSuper();
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"superSend",{})});
 //>>excludeEnd("ctx");

+ 1 - 1
lang/src/Compiler-AST.st

@@ -482,7 +482,7 @@ selector: aString
 !
 
 superSend
-	^ self receiver notNil and: [ self receiver isSuper ]
+	^ self receiver ifNil: [ false ] ifNotNil: [ :recv | recv isSuper ]
 ! !
 
 !SendNode methodsFor: 'testing'!

+ 11 - 17
lang/src/Compiler-Semantic.js

@@ -346,31 +346,25 @@ selector: "isInlined",
 protocol: "testing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "isInlined\x0a\x09^ self instruction notNil and: [\x0a\x09\x09self instruction isInlined ]",
+source: "isInlined\x0a\x09^ self instruction ifNil: [ false ] ifNotNil: [ :instr | instr isInlined ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["and:", "notNil", "instruction", "isInlined"]
+messageSends: ["ifNil:ifNotNil:", "instruction", "isInlined"]
 }, function ($methodClass){ return function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $2,$1;
-$2=$self._instruction();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["instruction"]=1;
-//>>excludeEnd("ctx");
-$1=$recv($2)._notNil();
-return $recv($1)._and_((function(){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-return $recv($self._instruction())._isInlined();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
-//>>excludeEnd("ctx");
-}));
+var $1,$receiver;
+$1=$self._instruction();
+if(($receiver = $1) == null || $receiver.a$nil){
+return false;
+} else {
+var instr;
+instr=$receiver;
+return $recv(instr)._isInlined();
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"isInlined",{})});
 //>>excludeEnd("ctx");

+ 1 - 2
lang/src/Compiler-Semantic.st

@@ -117,8 +117,7 @@ isBlockScope
 !
 
 isInlined
-	^ self instruction notNil and: [
-		self instruction isInlined ]
+	^ self instruction ifNil: [ false ] ifNotNil: [ :instr | instr isInlined ]
 !
 
 isMethodScope

+ 11 - 17
lang/src/Kernel-Classes.js

@@ -326,35 +326,29 @@ selector: "canUnderstand:",
 protocol: "testing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aSelector"],
-source: "canUnderstand: aSelector\x0a\x09^ (self includesSelector: aSelector asString) or: [\x0a\x09\x09self superclass notNil and: [ self superclass canUnderstand: aSelector ]]",
+source: "canUnderstand: aSelector\x0a\x09^ (self includesSelector: aSelector asString) or: [\x0a\x09\x09self superclass ifNil: [ false ] ifNotNil: [ :superClass | superClass canUnderstand: aSelector ]]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["or:", "includesSelector:", "asString", "and:", "notNil", "superclass", "canUnderstand:"]
+messageSends: ["or:", "includesSelector:", "asString", "ifNil:ifNotNil:", "superclass", "canUnderstand:"]
 }, function ($methodClass){ return function (aSelector){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $2,$1;
+var $1,$receiver;
 return $recv($self._includesSelector_($recv(aSelector)._asString()))._or_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$2=$self._superclass();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx2.sendIdx["superclass"]=1;
-//>>excludeEnd("ctx");
-$1=$recv($2)._notNil();
-return $recv($1)._and_((function(){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx3) {
-//>>excludeEnd("ctx");
-return $recv($self._superclass())._canUnderstand_(aSelector);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
-//>>excludeEnd("ctx");
-}));
+$1=$self._superclass();
+if(($receiver = $1) == null || $receiver.a$nil){
+return false;
+} else {
+var superClass;
+superClass=$receiver;
+return $recv(superClass)._canUnderstand_(aSelector);
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");

+ 1 - 1
lang/src/Kernel-Classes.st

@@ -171,7 +171,7 @@ makeJavaScriptConstructorSubclassOf: javaScriptClass
 
 canUnderstand: aSelector
 	^ (self includesSelector: aSelector asString) or: [
-		self superclass notNil and: [ self superclass canUnderstand: aSelector ]]
+		self superclass ifNil: [ false ] ifNotNil: [ :superClass | superClass canUnderstand: aSelector ]]
 !
 
 includesBehavior: aClass

+ 4 - 14
lang/src/Kernel-Helpers.js

@@ -196,29 +196,19 @@ selector: "canProcessPragma:",
 protocol: "pragma processing",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aMessage"],
-source: "canProcessPragma: aMessage\x0a\x09| selector |\x0a\x09selector := aMessage selector.\x0a\x09^ (self respondsTo: selector) and: [\x0a\x09\x09(self class superclass canUnderstand: selector) not]",
+source: "canProcessPragma: aMessage\x0a\x09^ self class includesSelector: aMessage selector",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["selector", "and:", "respondsTo:", "not", "canUnderstand:", "superclass", "class"]
+messageSends: ["includesSelector:", "class", "selector"]
 }, function ($methodClass){ return function (aMessage){
 var self=this,$self=this;
-var selector;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-selector=$recv(aMessage)._selector();
-return $recv($self._respondsTo_(selector))._and_((function(){
+return $recv($self._class())._includesSelector_($recv(aMessage)._selector());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-return $recv($recv($recv($self._class())._superclass())._canUnderstand_(selector))._not();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
-//>>excludeEnd("ctx");
-}));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"canProcessPragma:",{aMessage:aMessage,selector:selector})});
+}, function($ctx1) {$ctx1.fill(self,"canProcessPragma:",{aMessage:aMessage})});
 //>>excludeEnd("ctx");
 }; }),
 $globals.TPragmator);

+ 1 - 4
lang/src/Kernel-Helpers.st

@@ -56,10 +56,7 @@ Trait named: #TPragmator
 !TPragmator methodsFor: 'pragma processing'!
 
 canProcessPragma: aMessage
-	| selector |
-	selector := aMessage selector.
-	^ (self respondsTo: selector) and: [
-		(self class superclass canUnderstand: selector) not]
+	^ self class includesSelector: aMessage selector
 !
 
 processPragma: aMessage