From 879ec1b385d290a4375682ec613a9e7a1967fc7d Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 10 Oct 2018 13:56:25 -0400 Subject: Feature/source loc refactor (#668) * * Remove the need for IRHighLevelDecoration in Emit * Use the IRLayoutDecoration for GeometryShaderPrimitiveTypeModifier * Initial look at at variable byte encoding, and simple unit test. * Fixing problems with comparison due to naming differences with slang/fxc. * * More tests and perf improvements for byte encoding. * Mechanism to detect processor and processor features in main slang header. * Split out cpu based defines into slang-cpu-defines.h so do not polute slang.h * Support for variable byte encoding on serialization. * Removed unused flag. * Fix warning. * Fix calcMsByte32 for 0 values without using intrinsic. * Fix a mistake in calculating maximum instruction size. * Introduced the idea of SourceUnit. * Small improvements around naming. Add more functionality - including getting the HumaneLoc. * Add support for #line default * Compiling with new SourceLoc handling. * Fix off by one on #line directives. * Can use 32bits for SourceLoc. Fix serialize to use that. * Small fixes and comment on usage. * Premake run. * Fix signed warning. * Fix typo on StringSlicePool::has found in review. --- source/core/slang-string-slice-pool.cpp | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 source/core/slang-string-slice-pool.cpp (limited to 'source/core/slang-string-slice-pool.cpp') diff --git a/source/core/slang-string-slice-pool.cpp b/source/core/slang-string-slice-pool.cpp new file mode 100644 index 000000000..88963d68f --- /dev/null +++ b/source/core/slang-string-slice-pool.cpp @@ -0,0 +1,43 @@ +#include "slang-string-slice-pool.h" + +namespace Slang { + +StringSlicePool::StringSlicePool() : + m_arena(1024) +{ + clear(); +} + +void StringSlicePool::clear() +{ + m_slices.SetSize(1); + m_slices[0] = UnownedStringSlice::fromLiteral(""); + + m_map.Clear(); +} + +StringSlicePool::Handle StringSlicePool::add(const Slice& slice) +{ + const int* indexPtr = m_map.TryGetValue(slice); + if (indexPtr) + { + return Handle(*indexPtr); + } + + // Create a scoped copy + UnownedStringSlice scopePath(m_arena.allocateString(slice.begin(), slice.size()), slice.size()); + + const int index = int(m_slices.Count()); + + m_slices.Add(scopePath); + m_map.Add(scopePath, index); + return Handle(index); +} + +int StringSlicePool::findIndex(const Slice& slice) const +{ + const int* index = m_map.TryGetValue(slice); + return index ? *index : -1; + +} +} // namespace Slang -- cgit v1.2.3