Browse Source

Memoize st2js internal use.

Herby Vojčík 5 years ago
parent
commit
9e0cf32dd4
1 changed files with 11 additions and 1 deletions
  1. 11 1
      lang/base/kernel-runtime.js

+ 11 - 1
lang/base/kernel-runtime.js

@@ -388,8 +388,10 @@ define(function () {
     }
 
     function SelectorConversionBrik (brikz, st) {
+        var st2jsMemo = Object.create(null);
+
         /* Convert a Smalltalk selector into a JS selector */
-        st.st2js = this.st2js = function (string) {
+        function st2js (string) {
             return '_' + string
                 .replace(/:/g, '_')
                 .replace(/[\&]/g, '_and')
@@ -408,6 +410,14 @@ define(function () {
                 .replace(/[@]/g, '_at');
         };
 
+        st.st2js = function (stSelector) {
+            return st2jsMemo[stSelector] || st2js(stSelector);
+        };
+
+        this.st2js = function (stSelector) {
+            return st2jsMemo[stSelector] || (st2jsMemo[stSelector] = st2js(stSelector));
+        };
+
         /* Convert a string to a valid smalltalk selector.
          if you modify the following functions, also change st2js
          accordingly */