You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2020/12/31 07:12:15 UTC

[royale-asjs] branch develop updated: Speed up "x as y" and "x is y" where y is an interface, by flattening and caching results from checkInterfaces() inside Language.is().

This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new e5194d3  Speed up "x as y" and "x is y" where y is an interface, by flattening and caching results from checkInterfaces() inside Language.is().
     new 8364b86  Merge pull request #1026 from estanglerbm/language-faster-checkinterfaces
e5194d3 is described below

commit e5194d37c2d013fe95f640b477a674e3704936dc
Author: Edward Stangler <es...@bradmark.com>
AuthorDate: Thu Dec 31 00:32:12 2020 -0600

    Speed up "x as y" and "x is y" where y is an interface, by flattening and caching results from checkInterfaces() inside Language.is().
---
 .../royale/org/apache/royale/utils/Language.as     | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/frameworks/projects/Language/src/main/royale/org/apache/royale/utils/Language.as b/frameworks/projects/Language/src/main/royale/org/apache/royale/utils/Language.as
index 368521e..7b4a60d 100644
--- a/frameworks/projects/Language/src/main/royale/org/apache/royale/utils/Language.as
+++ b/frameworks/projects/Language/src/main/royale/org/apache/royale/utils/Language.as
@@ -56,6 +56,12 @@ package org.apache.royale.utils
         static private var muler:Number;
         static private var zeroStr:String = String.fromCharCode(0);
         
+        /**
+         * Var for speeding up checkInterfaces()
+         */
+        static private var interfaceMap:Object = null;
+        static private var isInitInterfaceMap:Boolean = false;
+        
         //--------------------------------------
         //   Static Function
         //--------------------------------------
@@ -172,11 +178,40 @@ package org.apache.royale.utils
             
             if (leftOperand.ROYALE_CLASS_INFO === undefined)
                 return false; // could be a function but not an instance
+
+            if (!isInitInterfaceMap)
+            {
+                if (typeof WeakMap == "function")
+                {
+                	    interfaceMap = new WeakMap();
+                }
+                isInitInterfaceMap = true;
+            }
+
+            var classInterfaceMap:Object;
+
+            // check interface check cache
+            if (interfaceMap && interfaceMap.has(leftOperand.ROYALE_CLASS_INFO))
+            {
+                classInterfaceMap = interfaceMap.get(leftOperand.ROYALE_CLASS_INFO);
+                if (classInterfaceMap && classInterfaceMap.has(rightOperand))
+                    return classInterfaceMap.get(rightOperand);
+            }
             
             if (leftOperand.ROYALE_CLASS_INFO.interfaces)
             {
                 if (checkInterfaces(leftOperand, rightOperand))
                 {
+                    // update interface check cache
+                    if (interfaceMap)
+                    {
+                        if (!interfaceMap.has(leftOperand.ROYALE_CLASS_INFO))
+                        {
+                            interfaceMap.set(leftOperand.ROYALE_CLASS_INFO, new WeakMap());
+                        }
+                        classInterfaceMap = interfaceMap.get(leftOperand.ROYALE_CLASS_INFO);
+                        classInterfaceMap.set(rightOperand, true);
+                    }
                     return true;
                 }
             }
@@ -191,6 +226,16 @@ package org.apache.royale.utils
                     {
                         if (checkInterfaces(superClass, rightOperand))
                         {
+                            // update interface check cache
+                            if (interfaceMap)
+                            {
+                                if (!interfaceMap.has(leftOperand.ROYALE_CLASS_INFO))
+                                {
+                                    interfaceMap.set(leftOperand.ROYALE_CLASS_INFO, new WeakMap());
+                                }
+                                classInterfaceMap = interfaceMap.get(leftOperand.ROYALE_CLASS_INFO);
+                                classInterfaceMap.set(rightOperand, true);
+                            }
                             return true;
                         }
                     }
@@ -198,6 +243,16 @@ package org.apache.royale.utils
                 }
             }
             
+            // update interface check cache
+            if (interfaceMap)
+            {
+                if (!interfaceMap.has(leftOperand.ROYALE_CLASS_INFO))
+                {
+                    interfaceMap.set(leftOperand.ROYALE_CLASS_INFO, new WeakMap());
+                }
+                classInterfaceMap = interfaceMap.get(leftOperand.ROYALE_CLASS_INFO);
+                classInterfaceMap.set(rightOperand, false);
+            }
             return false;
         }