summaryrefslogtreecommitdiffstats
path: root/source/core/slang-string-slice-pool.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-10-30 15:31:27 -0400
committerGitHub <noreply@github.com>2018-10-30 15:31:27 -0400
commitbaf06088dff0b961843ad03efd75ff009befec5c (patch)
tree6720c4b5015ff50dd14d7654d5d3fdae01a6ef7e /source/core/slang-string-slice-pool.h
parent2a7644980035bfda0aab00f183154ab7e976ba63 (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.h')
-rw-r--r--source/core/slang-string-slice-pool.h17
1 files changed, 16 insertions, 1 deletions
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<UnownedStringSlice>& 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<UnownedStringSlice> m_slices;
- Dictionary<UnownedStringSlice, int> m_map;
+ Dictionary<UnownedStringSlice, Handle> m_map;
MemoryArena m_arena;
};