From 100a3a3053d3010acf2867983ec14a7996cddb53 Mon Sep 17 00:00:00 2001 From: YairBybabayov Date: Sun, 25 Aug 2024 22:01:38 +0300 Subject: [PATCH] chached functions --- elenasrc3/elc/clicommon.h | 10 +++++++++- elenasrc3/elc/compilerlogic.cpp | 32 +++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/elenasrc3/elc/clicommon.h b/elenasrc3/elc/clicommon.h index 7c6a785e0..0df9cd33d 100644 --- a/elenasrc3/elc/clicommon.h +++ b/elenasrc3/elc/clicommon.h @@ -300,6 +300,10 @@ class ModuleScopeBase : public SectionScopeBase Map cachedClassReferences; Map cachedEmbeddableReadonlys; Map cachedEmbeddables; + Map cachedEmbeddableStructs; + Map cachedEmbeddableArrays; + Map cachedStacksafeArgs; + Map cachedWrappers; virtual bool isStandardOne() = 0; virtual bool withValidation() = 0; @@ -369,7 +373,11 @@ class ModuleScopeBase : public SectionScopeBase cachedSizes({}), cachedClassReferences(0), cachedEmbeddableReadonlys(false), - cachedEmbeddables(false) + cachedEmbeddables(false), + cachedEmbeddableStructs(false), + cachedEmbeddableArrays(false), + cachedStacksafeArgs(false), + cachedWrappers(false) { this->module = module; this->debugModule = debugModule; diff --git a/elenasrc3/elc/compilerlogic.cpp b/elenasrc3/elc/compilerlogic.cpp index 519184bd4..af989ed55 100644 --- a/elenasrc3/elc/compilerlogic.cpp +++ b/elenasrc3/elc/compilerlogic.cpp @@ -1306,9 +1306,16 @@ bool CompilerLogic :: isReadOnly(ClassInfo& info) bool CompilerLogic :: isEmbeddableArray(ModuleScopeBase& scope, ref_t reference) { + if (scope.cachedEmbeddableArrays.exist(reference)) + return scope.cachedEmbeddableArrays.get(reference); + ClassInfo info; if (defineClassInfo(scope, info, reference, true)) { - return isEmbeddableArray(info); + auto retVal = isEmbeddableArray(info); + + scope.cachedEmbeddableArrays.add(reference, retVal); + + return retVal; } return false; @@ -1388,10 +1395,15 @@ bool CompilerLogic :: isEmbeddableStruct(ModuleScopeBase& scope, TypeInfo typeIn if (typeInfo.nillable) return false; + if (scope.cachedEmbeddableStructs.exist(typeInfo.typeRef)) + return scope.cachedEmbeddableStructs.get(typeInfo.typeRef); + ClassInfo info; if (defineClassInfo(scope, info, typeInfo.typeRef, true)) { auto retVal = isEmbeddableStruct(info); + scope.cachedEmbeddableStructs.add(typeInfo.typeRef, retVal); + return retVal; } @@ -1408,9 +1420,16 @@ bool CompilerLogic :: isStacksafeArg(ClassInfo& info) bool CompilerLogic :: isStacksafeArg(ModuleScopeBase& scope, ref_t reference) { + if (scope.cachedStacksafeArgs.exist(reference)) + return scope.cachedStacksafeArgs.get(reference); + ClassInfo info; if (defineClassInfo(scope, info, reference, true)) { - return isStacksafeArg(info); + auto retVal = isStacksafeArg(info); + + scope.cachedStacksafeArgs.add(reference, retVal); + + return retVal; } return false; @@ -1418,9 +1437,16 @@ bool CompilerLogic :: isStacksafeArg(ModuleScopeBase& scope, ref_t reference) bool CompilerLogic :: isWrapper(ModuleScopeBase& scope, ref_t reference) { + if (scope.cachedWrappers.exist(reference)) + return scope.cachedWrappers.get(reference); + ClassInfo info; if (defineClassInfo(scope, info, reference, true)) { - return isWrapper(info); + auto retVal = isWrapper(info); + + scope.cachedWrappers.add(reference, retVal); + + return retVal; } return false;