diff options
Diffstat (limited to 'source/slang/slang-serialize.cpp')
| -rw-r--r-- | source/slang/slang-serialize.cpp | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/source/slang/slang-serialize.cpp b/source/slang/slang-serialize.cpp index 34680d860..4f8fdc546 100644 --- a/source/slang/slang-serialize.cpp +++ b/source/slang/slang-serialize.cpp @@ -151,6 +151,58 @@ SerialClass* SerialClasses::_createSerialClass(const SerialClass* cls) return dst; } +bool SerialClasses::isOk() const +{ + StringSlicePool pool(StringSlicePool::Style::Default); + + for (const auto& classes : m_classesByTypeKind) + { + for (const SerialClass* cls : classes) + { + // It is possible potentially to have gaps + if (cls == nullptr) + { + continue; + } + + if (cls->super && cls->super->typeKind != cls->typeKind) + { + // If has a super type, must be the same typeKind + return false; + } + + // Make sure the fields are uniquely named + + pool.clear(); + + { + const SerialClass* curCls = cls; + + do + { + for (Index i = 0; i < curCls->fieldsCount; ++i) + { + const SerialField& field = curCls->fields[i]; + + StringSlicePool::Handle handle; + if (pool.findOrAdd(UnownedStringSlice(field.name), handle)) + { + return false; + } + } + + // Add the fields of the parent + curCls = curCls->super; + } + while (curCls); + } + } + } + + return true; +} + + SerialClasses::SerialClasses(): m_arena(2048) { @@ -375,7 +427,7 @@ SerialIndex SerialWriter::addName(const Name* name) return index; } -SerialIndex SerialWriter::_addArray(size_t elementSize, size_t alignment, const void* elements, Index elementCount) +SerialIndex SerialWriter::addSerialArray(size_t elementSize, size_t alignment, const void* elements, Index elementCount) { typedef SerialInfo::ArrayEntry Entry; @@ -699,12 +751,19 @@ String SerialReader::getString(SerialIndex index) // Okay we need to construct as a string UnownedStringSlice slice = getStringSlice(index); - String string(slice); - StringRepresentation* stringRep = string.getStringRepresentation(); - m_scope.add(stringRep); + StringRepresentation* stringRep = nullptr; + + const Index length = slice.getLength(); + if (length) + { + stringRep = StringRepresentation::createWithCapacityAndLength(length, length); + memcpy(stringRep->getData(), slice.begin(), length * sizeof(char)); + addScope(stringRep); + } + m_objects[Index(index)] = stringRep; - return string; + return String(stringRep); } Name* SerialReader::getName(SerialIndex index) |
