Browse Source

just for fun optimization play

Herbert Vojčík 9 years ago
parent
commit
ea99ce9aea
4 changed files with 53 additions and 38 deletions
  1. 17 17
      src/Kernel-Collections.js
  2. 16 15
      src/Kernel-Collections.st
  3. 10 4
      src/Kernel-Objects.js
  4. 10 2
      src/Kernel-Objects.st

+ 17 - 17
src/Kernel-Collections.js

@@ -5896,7 +5896,10 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return aString != null && String(self) === (typeof aString === "string" ? aString : aString.valueOf());
+
+	if (typeof aString === "string") return String(self) === aString;
+	else if (aString != null && typeof aString === "object") return String(self) === aString.valueOf();
+	else return false;;
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"==",{aString:aString},$globals.String)});
@@ -5904,7 +5907,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aString"],
-source: "== aString\x0a<return aString != null && String(self) === (typeof aString === \x22string\x22 ? aString : aString.valueOf())>",
+source: "== aString\x0a<\x0a\x09if (typeof aString === \x22string\x22) return String(self) === aString;\x0a\x09else if (aString != null && typeof aString === \x22object\x22) return String(self) === aString.valueOf();\x0a\x09else return false;\x0a>",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
@@ -7880,21 +7883,18 @@ var self=this;
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 
-		var type, bucket, prim = anObject == null ? (anObject = nil) : anObject.valueOf();
-		if ((type = typeof prim) === "object") {
-			if (anObject !== nil) {
-				bucket = null;
-				self['@slowBucketStores'].some(function (store) {
-					return bucket = store._bucketOfElement_(anObject);
-				});
-				return [ anObject, null, bucket || self['@defaultBucket'] ];
-			}
-			
-			// include nil to well-known objects under 'boolean' fastBucket
-			prim = null;
-			type = 'boolean';
+		// include nil to well-known objects under 'boolean' fastBucket
+		if (anObject == null || anObject.isNil) return [ null, self['@fastBuckets'].boolean ];
+		
+		var prim = anObject.valueOf();
+		if (typeof prim === "object") {
+			var bucket = null;
+			self['@slowBucketStores'].some(function (store) {
+				return bucket = store._bucketOfElement_(anObject);
+			});
+			return [ anObject, null, bucket || self['@defaultBucket'] ];
 		}
-		return [ prim, self['@fastBuckets'][type] ];
+		return [ prim, self['@fastBuckets'][typeof prim] ];
 	;
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -7903,7 +7903,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anObject"],
-source: "bucketsOfElement: anObject\x0a\x09\x22Find the appropriate bucket for `anObject`.\x0a\x09For optimization purposes, directly answer an array with: \x0a\x09- the object to be store\x0a\x09- the primitive bucket\x0a\x09- the slow bucket\x22\x0a\x09\x0a\x09<\x0a\x09\x09var type, bucket, prim = anObject == null ? (anObject = nil) : anObject.valueOf();\x0a\x09\x09if ((type = typeof prim) === \x22object\x22) {\x0a\x09\x09\x09if (anObject !== nil) {\x0a\x09\x09\x09\x09bucket = null;\x0a\x09\x09\x09\x09self['@slowBucketStores'].some(function (store) {\x0a\x09\x09\x09\x09\x09return bucket = store._bucketOfElement_(anObject);\x0a\x09\x09\x09\x09});\x0a\x09\x09\x09\x09return [ anObject, null, bucket || self['@defaultBucket'] ];\x0a\x09\x09\x09}\x0a\x09\x09\x09\x0a\x09\x09\x09// include nil to well-known objects under 'boolean' fastBucket\x0a\x09\x09\x09prim = null;\x0a\x09\x09\x09type = 'boolean';\x0a\x09\x09}\x0a\x09\x09return [ prim, self['@fastBuckets'][type] ];\x0a\x09>",
+source: "bucketsOfElement: anObject\x0a\x09\x22Find the appropriate bucket for `anObject`.\x0a\x09For optimization purposes, directly answer an array with: \x0a\x09- the object to be store\x0a\x09- the primitive bucket\x0a\x09- the slow bucket\x22\x0a\x09\x0a\x09<\x0a\x09\x09// include nil to well-known objects under 'boolean' fastBucket\x0a\x09\x09if (anObject == null || anObject.isNil) return [ null, self['@fastBuckets'].boolean ];\x0a\x09\x09\x0a\x09\x09var prim = anObject.valueOf();\x0a\x09\x09if (typeof prim === \x22object\x22) {\x0a\x09\x09\x09var bucket = null;\x0a\x09\x09\x09self['@slowBucketStores'].some(function (store) {\x0a\x09\x09\x09\x09return bucket = store._bucketOfElement_(anObject);\x0a\x09\x09\x09});\x0a\x09\x09\x09return [ anObject, null, bucket || self['@defaultBucket'] ];\x0a\x09\x09}\x0a\x09\x09return [ prim, self['@fastBuckets'][typeof prim] ];\x0a\x09>",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []

+ 16 - 15
src/Kernel-Collections.st

@@ -1473,7 +1473,11 @@ size
 !
 
 == aString
-<return aString !!= null && String(self) === (typeof aString === "string" ? aString : aString.valueOf())>
+<
+	if (typeof aString === "string") return String(self) === aString;
+	else if (aString !!= null && typeof aString === "object") return String(self) === aString.valueOf();
+	else return false;
+>
 !
 
 > aString
@@ -1986,21 +1990,18 @@ bucketsOfElement: anObject
 	- the slow bucket"
 	
 	<
-		var type, bucket, prim = anObject == null ? (anObject = nil) : anObject.valueOf();
-		if ((type = typeof prim) === "object") {
-			if (anObject !!== nil) {
-				bucket = null;
-				self['@slowBucketStores'].some(function (store) {
-					return bucket = store._bucketOfElement_(anObject);
-				});
-				return [ anObject, null, bucket || self['@defaultBucket'] ];
-			}
-			
-			// include nil to well-known objects under 'boolean' fastBucket
-			prim = null;
-			type = 'boolean';
+		// include nil to well-known objects under 'boolean' fastBucket
+		if (anObject == null || anObject.isNil) return [ null, self['@fastBuckets'].boolean ];
+		
+		var prim = anObject.valueOf();
+		if (typeof prim === "object") {
+			var bucket = null;
+			self['@slowBucketStores'].some(function (store) {
+				return bucket = store._bucketOfElement_(anObject);
+			});
+			return [ anObject, null, bucket || self['@defaultBucket'] ];
 		}
-		return [ prim, self['@fastBuckets'][type] ];
+		return [ prim, self['@fastBuckets'][typeof prim] ];
 	>
 !
 

+ 10 - 4
src/Kernel-Objects.js

@@ -1769,7 +1769,10 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return aBoolean != null && self.valueOf() === (typeof aBoolean === "boolean" ? aBoolean : aBoolean.valueOf());
+
+	if (typeof aBoolean === "boolean") return self.valueOf() === aBoolean;
+	else if (aBoolean != null && typeof aBoolean === "object") return self.valueOf() === aBoolean.valueOf();
+	else return false;;
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"==",{aBoolean:aBoolean},$globals.Boolean)});
@@ -1777,7 +1780,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aBoolean"],
-source: "== aBoolean\x0a<return aBoolean != null && self.valueOf() === (typeof aBoolean === \x22boolean\x22 ? aBoolean : aBoolean.valueOf())>",
+source: "== aBoolean\x0a<\x0a\x09if (typeof aBoolean === \x22boolean\x22) return self.valueOf() === aBoolean;\x0a\x09else if (aBoolean != null && typeof aBoolean === \x22object\x22) return self.valueOf() === aBoolean.valueOf();\x0a\x09else return false;\x0a>",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []
@@ -3416,7 +3419,10 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return aNumber != null && Number(self) === (typeof aNumber === "number" ? aNumber : aNumber.valueOf());
+
+	if (typeof aNumber === "number") return Number(self) === aNumber;
+	else if (aNumber != null && typeof aNumber === "object") return Number(self) === aNumber.valueOf();
+	else return false;;
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"==",{aNumber:aNumber},$globals.Number)});
@@ -3424,7 +3430,7 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aNumber"],
-source: "== aNumber\x0a<return aNumber != null && Number(self) === (typeof aNumber === \x22number\x22 ? aNumber : aNumber.valueOf())>",
+source: "== aNumber\x0a<\x0a\x09if (typeof aNumber === \x22number\x22) return Number(self) === aNumber;\x0a\x09else if (aNumber != null && typeof aNumber === \x22object\x22) return Number(self) === aNumber.valueOf();\x0a\x09else return false;\x0a>",
 referencedClasses: [],
 //>>excludeEnd("ide");
 messageSends: []

+ 10 - 2
src/Kernel-Objects.st

@@ -434,7 +434,11 @@ I am directly mapped to JavaScript Boolean. The `true` and `false` objects are t
 !Boolean methodsFor: 'comparing'!
 
 == aBoolean
-<return aBoolean !!= null && self.valueOf() === (typeof aBoolean === "boolean" ? aBoolean : aBoolean.valueOf())>
+<
+	if (typeof aBoolean === "boolean") return self.valueOf() === aBoolean;
+	else if (aBoolean !!= null && typeof aBoolean === "object") return self.valueOf() === aBoolean.valueOf();
+	else return false;
+>
 ! !
 
 !Boolean methodsFor: 'controlling'!
@@ -826,7 +830,11 @@ negated
 !
 
 == aNumber
-<return aNumber !!= null && Number(self) === (typeof aNumber === "number" ? aNumber : aNumber.valueOf())>
+<
+	if (typeof aNumber === "number") return Number(self) === aNumber;
+	else if (aNumber !!= null && typeof aNumber === "object") return Number(self) === aNumber.valueOf();
+	else return false;
+>
 !
 
 > aNumber