浏览代码

Performance optimization.

Herby Vojčík 4 年之前
父节点
当前提交
c50db69cf5
共有 1 个文件被更改,包括 21 次插入15 次删除
  1. 21 15
      lang/base/junk-drawer.js

+ 21 - 15
lang/base/junk-drawer.js

@@ -27,24 +27,30 @@ define(function () {
         if (obj[name] == null) installMethodOfJsObject(obj, name, noop);
     }
 
+    var table = {
+        ':': '_',
+        '&': '_and',
+        '|': '_or',
+        '+': '_plus',
+        '-': '_minus',
+        '*': '_star',
+        '/': '_slash',
+        '\\': '_backslash',
+        '~': '_tild',
+        '%': '_percent',
+        '>': '_gt',
+        '<': '_lt',
+        '=': '_eq',
+        ',': '_comma',
+        '@': '_at'
+    };
+
     /* Convert a Smalltalk selector into a JS selector */
     function st2js (string) {
         return '_' + string
-            .replace(/:/g, '_')
-            .replace(/[\&]/g, '_and')
-            .replace(/[\|]/g, '_or')
-            .replace(/[+]/g, '_plus')
-            .replace(/-/g, '_minus')
-            .replace(/[*]/g, '_star')
-            .replace(/[\/]/g, '_slash')
-            .replace(/[\\]/g, '_backslash')
-            .replace(/[\~]/g, '_tild')
-            .replace(/%/g, '_percent')
-            .replace(/>/g, '_gt')
-            .replace(/</g, '_lt')
-            .replace(/=/g, '_eq')
-            .replace(/,/g, '_comma')
-            .replace(/[@]/g, '_at');
+            .replace(/[:&|+\-*/\\~%><=,@]/g, function (ch) {
+                return table[ch];
+            });
     };
 
     function js2st (selector) {