[NFC] Refactor manual size calculations in memory allocation (#33256)

This commit is contained in:
Matei Oprea
2020-08-04 08:02:31 +03:00
committed by GitHub
parent 0153cffb02
commit f971b349b4
5 changed files with 13 additions and 19 deletions

View File

@@ -139,12 +139,9 @@ ImportCache::getImportSet(ASTContext &ctx,
// getImportedModulesForLookup().
if (ImportSet *result = ImportSets.FindNodeOrInsertPos(ID, InsertPos))
return *result;
void *mem = ctx.Allocate(
sizeof(ImportSet) +
sizeof(ModuleDecl::ImportedModule) * topLevelImports.size() +
sizeof(ModuleDecl::ImportedModule) * transitiveImports.size(),
alignof(ImportSet), AllocationArena::Permanent);
size_t bytes = ImportSet::totalSizeToAlloc<ModuleDecl::ImportedModule>(topLevelImports.size() + transitiveImports.size());
void *mem = ctx.Allocate(bytes, alignof(ImportSet), AllocationArena::Permanent);
auto *result = new (mem) ImportSet(hasHeaderImportModule,
topLevelImports,