From baf06088dff0b961843ad03efd75ff009befec5c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 30 Oct 2018 15:31:27 -0400 Subject: 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. --- source/core/slang-string-slice-pool.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source/core/slang-string-slice-pool.h') diff --git a/source/core/slang-string-slice-pool.h b/source/core/slang-string-slice-pool.h index e6846b3dd..c9c8b8db9 100644 --- a/source/core/slang-string-slice-pool.h +++ b/source/core/slang-string-slice-pool.h @@ -12,10 +12,16 @@ namespace Slang { class StringSlicePool { public: + /// Handle of 0 is null. If accessed will be returned as the empty string enum class Handle : uint32_t; typedef UnownedStringSlice Slice; + static const Handle kNullHandle = Handle(0); + static const Handle kEmptyHandle = Handle(1); + + static const int kNumDefaultHandles = 2; + /// Returns the index of a slice, if contained, or -1 if not found int findIndex(const Slice& slice) const; @@ -23,6 +29,12 @@ public: bool has(const Slice& slice) { return findIndex(slice) >= 0; } /// Add a slice Handle add(const Slice& slice); + /// Add from a string + Handle add(const char* chars); + /// Add a StringRepresentation + Handle add(StringRepresentation* string); + /// Add a string + Handle add(const String& string) { return add(string.getUnownedSlice()); } /// Empty contents void clear(); @@ -33,6 +45,9 @@ public: /// Get all the slices const List& getSlices() const { return m_slices; } + /// Get the number of slices + int getNumSlices() const { return int(m_slices.Count()); } + /// Convert a handle to and index. (A handle is just an index!) static int asIndex(Handle handle) { return int(handle); } @@ -41,7 +56,7 @@ public: protected: List m_slices; - Dictionary m_map; + Dictionary m_map; MemoryArena m_arena; }; -- cgit v1.2.3