diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-10-30 15:31:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-30 15:31:27 -0400 |
| commit | baf06088dff0b961843ad03efd75ff009befec5c (patch) | |
| tree | 6720c4b5015ff50dd14d7654d5d3fdae01a6ef7e /source/core/slang-string-slice-pool.cpp | |
| parent | 2a7644980035bfda0aab00f183154ab7e976ba63 (diff) | |
Feature/serial string pool refactor (#702)
* Ongoing serialization for full debug work.
* Use StringRepresentationCache and StringSlicePool for serialization.
* Removed some older path handling for serialization which had some wrong underlying assumptions.
* Builds with refactored use of SubStringPool in ir-serialize.
* Removed prohibitedCategories because not used anywhere.
* Add category 'compatibility-issue'
* Remove work in progress on debug serialization.
Diffstat (limited to 'source/core/slang-string-slice-pool.cpp')
| -rw-r--r-- | source/core/slang-string-slice-pool.cpp | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/source/core/slang-string-slice-pool.cpp b/source/core/slang-string-slice-pool.cpp index 88963d68f..797da5a0f 100644 --- a/source/core/slang-string-slice-pool.cpp +++ b/source/core/slang-string-slice-pool.cpp @@ -2,6 +2,12 @@ namespace Slang { +/* static */ const StringSlicePool::Handle StringSlicePool::kNullHandle; +/* static */ const StringSlicePool::Handle StringSlicePool::kEmptyHandle; + +/* static */const int StringSlicePool::kNumDefaultHandles; + + StringSlicePool::StringSlicePool() : m_arena(1024) { @@ -10,18 +16,23 @@ StringSlicePool::StringSlicePool() : void StringSlicePool::clear() { - m_slices.SetSize(1); - m_slices[0] = UnownedStringSlice::fromLiteral(""); + m_slices.SetSize(2); + + m_slices[0] = UnownedStringSlice((const char*)nullptr, (const char*)nullptr); + m_slices[1] = UnownedStringSlice::fromLiteral(""); + + // Add the empty entry + m_map.Add(m_slices[1], kEmptyHandle); m_map.Clear(); } StringSlicePool::Handle StringSlicePool::add(const Slice& slice) { - const int* indexPtr = m_map.TryGetValue(slice); - if (indexPtr) + const Handle* handlePtr = m_map.TryGetValue(slice); + if (handlePtr) { - return Handle(*indexPtr); + return *handlePtr; } // Create a scoped copy @@ -30,14 +41,37 @@ StringSlicePool::Handle StringSlicePool::add(const Slice& slice) const int index = int(m_slices.Count()); m_slices.Add(scopePath); - m_map.Add(scopePath, index); + m_map.Add(scopePath, Handle(index)); return Handle(index); } +StringSlicePool::Handle StringSlicePool::add(StringRepresentation* stringRep) +{ + if (stringRep == nullptr) + { + return kNullHandle; + } + return add(StringRepresentation::asSlice(stringRep)); +} + + +StringSlicePool::Handle StringSlicePool::add(const char* chars) +{ + if (!chars) + { + return kNullHandle; + } + if (chars[0] == 0) + { + return kEmptyHandle; + } + return add(UnownedStringSlice(chars)); +} + int StringSlicePool::findIndex(const Slice& slice) const { - const int* index = m_map.TryGetValue(slice); - return index ? *index : -1; + const Handle* handlePtr = m_map.TryGetValue(slice); + return handlePtr ? int(*handlePtr) : -1; } } // namespace Slang |
