From 1d7a7f23874151372f2792e7307f50c54dae877f Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 28 Oct 2020 09:38:56 -0700 Subject: Add sequential ID cache in Linkage for witness tables and RTTI objects. (#1590) --- source/slang/slang.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source/slang/slang.cpp') 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) { -- cgit v1.2.3