Skip to content

Commit

Permalink
chached functions
Browse files Browse the repository at this point in the history
  • Loading branch information
YairBybabayov committed Aug 25, 2024
1 parent 9bbf8fc commit 100a3a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
10 changes: 9 additions & 1 deletion elenasrc3/elc/clicommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ class ModuleScopeBase : public SectionScopeBase
Map<ref_t, ref_t> cachedClassReferences;
Map<ref_t, bool> cachedEmbeddableReadonlys;
Map<ref_t, bool> cachedEmbeddables;
Map<ref_t, bool> cachedEmbeddableStructs;
Map<ref_t, bool> cachedEmbeddableArrays;
Map<ref_t, bool> cachedStacksafeArgs;
Map<ref_t, bool> cachedWrappers;

virtual bool isStandardOne() = 0;
virtual bool withValidation() = 0;
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 29 additions & 3 deletions elenasrc3/elc/compilerlogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -1408,19 +1420,33 @@ 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;
}

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;
Expand Down

0 comments on commit 100a3a3

Please sign in to comment.