Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Reflection/Metadata+Class.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 7 additions & 9 deletions Sources/Reflection/Properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T : NominalType>(nominalType: T, hashedType: HashedType) throws -> [Property.Description] {
let properties = try propertiesForNominalType(nominalType)
cachedProperties[hashedType] = properties
return properties
}

private func propertiesForNominalType<T : NominalType>(_ type: T) throws -> [Property.Description] {
internal func propertiesForNominalType<T : NominalType>(_ 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
Expand Down