summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-10-28 09:38:56 -0700
committerGitHub <noreply@github.com>2020-10-28 09:38:56 -0700
commit1d7a7f23874151372f2792e7307f50c54dae877f (patch)
tree0a50b840c25bc57f7cddee7a18af3e2f642f9f66 /source/slang/slang.cpp
parent13945a51d932fc42fc1f31723ae64070d90708de (diff)
Add sequential ID cache in Linkage for witness tables and RTTI objects. (#1590)
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 376376f24..ad4e82d4f 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -658,6 +658,36 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::getTypeConformanceWitnessMangled
return SLANG_OK;
}
+SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::getTypeConformanceWitnessSequentialID(
+ slang::TypeReflection* type,
+ slang::TypeReflection* interfaceType,
+ uint32_t* outId)
+{
+ auto subType = asInternal(type);
+ auto supType = asInternal(interfaceType);
+ auto name = getMangledNameForConformanceWitness(subType->getASTBuilder(), subType, supType);
+ auto interfaceName = getMangledTypeName(supType->getASTBuilder(), supType);
+ uint32_t resultIndex = 0;
+ if (mapMangledNameToRTTIObjectIndex.TryGetValue(name, resultIndex))
+ {
+ if (outId)
+ *outId = resultIndex;
+ return SLANG_OK;
+ }
+ auto idAllocator = mapInterfaceMangledNameToSequentialIDCounters.TryGetValue(interfaceName);
+ if (!idAllocator)
+ {
+ mapInterfaceMangledNameToSequentialIDCounters[interfaceName] = 0;
+ idAllocator = mapInterfaceMangledNameToSequentialIDCounters.TryGetValue(interfaceName);
+ }
+ resultIndex = (*idAllocator);
+ ++(*idAllocator);
+ mapMangledNameToRTTIObjectIndex[name] = resultIndex;
+ if (outId)
+ *outId = resultIndex;
+ return SLANG_OK;
+}
+
SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompileRequest(
SlangCompileRequest** outCompileRequest)
{