diff --git a/Sources/Reflection/Metadata+Class.swift b/Sources/Reflection/Metadata+Class.swift index abfa45e..3c39fa8 100644 --- a/Sources/Reflection/Metadata+Class.swift +++ b/Sources/Reflection/Metadata+Class.swift @@ -14,7 +14,7 @@ extension Metadata { } func properties() throws -> [Property.Description] { - let properties = try fetchAndSaveProperties(nominalType: self, hashedType: HashedType(pointer)) + let properties = try propertiesForNominalType(self) guard let superclass = superclass, String(describing: unsafeBitCast(superclass.pointer, to: Any.Type.self)) != "SwiftObject" else { return properties } diff --git a/Sources/Reflection/Properties.swift b/Sources/Reflection/Properties.swift index 212bfc7..07cb8a5 100644 --- a/Sources/Reflection/Properties.swift +++ b/Sources/Reflection/Properties.swift @@ -51,21 +51,19 @@ public func properties(_ type: Any.Type) throws -> [Property.Description] { if let properties = cachedProperties[hashedType] { return properties } else if let nominalType = Metadata.Struct(type: type) { - return try fetchAndSaveProperties(nominalType: nominalType, hashedType: hashedType) + let properties = try propertiesForNominalType(nominalType) + cachedProperties[hashedType] = properties + return properties } else if let nominalType = Metadata.Class(type: type) { - return try nominalType.properties() + let properties = try nominalType.properties() + cachedProperties[hashedType] = properties + return properties } else { throw ReflectionError.notStruct(type: type) } } -func fetchAndSaveProperties(nominalType: T, hashedType: HashedType) throws -> [Property.Description] { - let properties = try propertiesForNominalType(nominalType) - cachedProperties[hashedType] = properties - return properties -} - -private func propertiesForNominalType(_ type: T) throws -> [Property.Description] { +internal func propertiesForNominalType(_ type: T) throws -> [Property.Description] { guard type.nominalTypeDescriptor.numberOfFields != 0 else { return [] } guard let fieldTypes = type.fieldTypes, let fieldOffsets = type.fieldOffsets else { throw ReflectionError.unexpected