summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-serialize-types.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2020-06-30 12:25:27 -0700
committerGitHub <noreply@github.com>2020-06-30 12:25:27 -0700
commit8ced9d2a0efaca8f6dbdaf427be1db52844787b5 (patch)
tree20dc0a8d3ec838253823558fc4df8a82ddd1a910 /source/slang/slang-ir-serialize-types.cpp
parentdc44b08ec377106a0c6d1c022e2754d9e11c579f (diff)
Clean up unused code for IR object ownership (#1416)
There was a small but non-trivial amount of code across `IRModule`, the `ObjectScopeManager`, and `StringRepresentationCache` that had to do with managing the lifetimes of `RefObject`s that might be referenced by IR instructions (and thus need to be kept alive for the lifetime of the IR module). We have long since migrated to a model where IR instruction do not include owned references to `RefObject`s, so these facilities weren't actually needed. This streamlines `IRModule`'s declaration, and trims code that we aren't actually using. One note for the future is that the `StringRepresentationCache` no longer does what its name implies (it is not a cache of `StringRepresentation`s), so we should consider giving it a more narrowly scoped name. I didn't include that in this change because I wanted to keep the diffs narrow and easy to review. A follow-on renaming change should be trivial if/when we can agree on what the type should be called at this point. Alternatively, we could simply bake the functionality of `StringRepresentationCache` into he IR deserialiation logic itself, since that is the only code using it.
Diffstat (limited to 'source/slang/slang-ir-serialize-types.cpp')
-rw-r--r--source/slang/slang-ir-serialize-types.cpp81
1 files changed, 2 insertions, 79 deletions
diff --git a/source/slang/slang-ir-serialize-types.cpp b/source/slang/slang-ir-serialize-types.cpp
index a9d9baae0..b57c46b58 100644
--- a/source/slang/slang-ir-serialize-types.cpp
+++ b/source/slang/slang-ir-serialize-types.cpp
@@ -64,17 +64,13 @@ struct CharReader
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringRepresentationCache !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
StringRepresentationCache::StringRepresentationCache():
- m_stringTable(nullptr),
- m_namePool(nullptr),
- m_scopeManager(nullptr)
+ m_stringTable(nullptr)
{
}
-void StringRepresentationCache::init(const List<char>* stringTable, NamePool* namePool, ObjectScopeManager* scopeManager)
+void StringRepresentationCache::init(const List<char>* stringTable)
{
m_stringTable = stringTable;
- m_namePool = namePool;
- m_scopeManager = scopeManager;
// Decode the table
m_entries.setCount(StringSlicePool::kDefaultHandlesCount);
@@ -84,13 +80,11 @@ void StringRepresentationCache::init(const List<char>* stringTable, NamePool* na
Entry& entry = m_entries[0];
entry.m_numChars = 0;
entry.m_startIndex = 0;
- entry.m_object = nullptr;
}
{
Entry& entry = m_entries[1];
entry.m_numChars = 0;
entry.m_startIndex = 0;
- entry.m_object = nullptr;
}
{
@@ -106,7 +100,6 @@ void StringRepresentationCache::init(const List<char>* stringTable, NamePool* na
Entry entry;
entry.m_startIndex = uint32_t(reader.m_pos - start);
entry.m_numChars = len;
- entry.m_object = nullptr;
m_entries.add(entry);
@@ -117,38 +110,6 @@ void StringRepresentationCache::init(const List<char>* stringTable, NamePool* na
m_entries.compress();
}
-Name* StringRepresentationCache::getName(Handle handle)
-{
- if (handle == StringSlicePool::kNullHandle)
- {
- return nullptr;
- }
-
- Entry& entry = m_entries[int(handle)];
- if (entry.m_object)
- {
- Name* name = dynamicCast<Name>(entry.m_object);
- if (name)
- {
- return name;
- }
- StringRepresentation* stringRep = static_cast<StringRepresentation*>(entry.m_object);
- // Promote it to a name
- name = m_namePool->getName(String(stringRep));
- entry.m_object = name;
- return name;
- }
-
- Name* name = m_namePool->getName(String(getStringSlice(handle)));
- entry.m_object = name;
- return name;
-}
-
-String StringRepresentationCache::getString(Handle handle)
-{
- return String(getStringRepresentation(handle));
-}
-
UnownedStringSlice StringRepresentationCache::getStringSlice(Handle handle) const
{
const Entry& entry = m_entries[int(handle)];
@@ -157,44 +118,6 @@ UnownedStringSlice StringRepresentationCache::getStringSlice(Handle handle) cons
return UnownedStringSlice(start + entry.m_startIndex, int(entry.m_numChars));
}
-StringRepresentation* StringRepresentationCache::getStringRepresentation(Handle handle)
-{
- if (handle == StringSlicePool::kNullHandle || handle == StringSlicePool::kEmptyHandle)
- {
- return nullptr;
- }
-
- Entry& entry = m_entries[int(handle)];
- if (entry.m_object)
- {
- Name* name = dynamicCast<Name>(entry.m_object);
- if (name)
- {
- return name->text.getStringRepresentation();
- }
- return static_cast<StringRepresentation*>(entry.m_object);
- }
-
- const UnownedStringSlice slice = getStringSlice(handle);
- const UInt size = slice.getLength();
-
- StringRepresentation* stringRep = StringRepresentation::createWithCapacityAndLength(size, size);
- memcpy(stringRep->getData(), slice.begin(), size);
- entry.m_object = stringRep;
-
- // Keep the StringRepresentation in scope
- m_scopeManager->add(stringRep);
-
- return stringRep;
-}
-
-char* StringRepresentationCache::getCStr(Handle handle)
-{
- // It turns out StringRepresentation is always 0 terminated, so can just use that
- StringRepresentation* rep = getStringRepresentation(handle);
- return rep->getData();
-}
-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SerialStringTableUtil !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* static */void SerialStringTableUtil::encodeStringTable(const StringSlicePool& pool, List<char>& stringTable)