Prechádzať zdrojové kódy

Merge pull request #1050 from herby/faster-dnu

Much faster asJavaScriptSelector
Herbert Vojčík 9 rokov pred
rodič
commit
cc5f5f8bc2

+ 6 - 6
src/Kernel-Infrastructure.js

@@ -3619,13 +3619,13 @@ protocol: '*Kernel-Infrastructure',
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-var $1;
-$1=self._replace_with_("^([a-zA-Z0-9]*).*$","$1");
-return $1;
-}, function($ctx1) {$ctx1.fill(self,"asJavaScriptSelector",{},globals.String)})},
+
+	var colonPosition = self.indexOf(':');
+	return colonPosition === -1 ? self : self.slice(0, colonPosition);;
+return self}, function($ctx1) {$ctx1.fill(self,"asJavaScriptSelector",{},globals.String)})},
 args: [],
-source: "asJavaScriptSelector\x0a\x09\x22Return first keyword of the selector, without trailing colon.\x22\x0a\x09^ self replace: '^([a-zA-Z0-9]*).*$' with: '$1'",
-messageSends: ["replace:with:"],
+source: "asJavaScriptSelector\x0a<\x0a\x09var colonPosition = self.indexOf(':');\x0a\x09return colonPosition === -1 ? self : self.slice(0, colonPosition);\x0a>",
+messageSends: [],
 referencedClasses: []
 }),
 globals.String);

+ 4 - 2
src/Kernel-Infrastructure.st

@@ -1374,8 +1374,10 @@ do: aBlock displayingProgress: aString
 !String methodsFor: '*Kernel-Infrastructure'!
 
 asJavaScriptSelector
-	"Return first keyword of the selector, without trailing colon."
-	^ self replace: '^([a-zA-Z0-9]*).*$' with: '$1'
+<
+	var colonPosition = self.indexOf(':');
+	return colonPosition === -1 ? self : self.slice(0, colonPosition);
+>
 !
 
 asSetting