diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-10-10 13:56:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-10 13:56:25 -0400 |
| commit | 879ec1b385d290a4375682ec613a9e7a1967fc7d (patch) | |
| tree | 0d5f32d83d45458db54cce281c0c6331a677cdff /source/core/slang-string-slice-pool.cpp | |
| parent | 60a91d63afab47a172690974c8b566af74072932 (diff) | |
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.
Diffstat (limited to 'source/core/slang-string-slice-pool.cpp')
| -rw-r--r-- | source/core/slang-string-slice-pool.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
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 |
