Skip to content

Commit

Permalink
Fix memory leak due to mirror destructuring. (#20)
Browse files Browse the repository at this point in the history
* Fix memory leak due to mirror destructuring.

* Fix CI
  • Loading branch information
mbrandonw authored Jan 28, 2021
1 parent 469ef51 commit 1aa1bf7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ test-linux:

test-swift:
swift test \
--enable-pubgrub-resolver \
--enable-test-discovery \
--parallel

Expand Down
8 changes: 4 additions & 4 deletions Sources/CasePaths/EnumReflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public func extract<Root, Value>(case embed: (Value) -> Root, from root: Root) -
var path: [String?] = []
var any: Any = root

while case let (label?, anyChild)? = Mirror(reflecting: any).children.first {
while let child = Mirror(reflecting: any).children.first, let label = child.label {
path.append(label)
path.append(String(describing: type(of: anyChild)))
if let child = anyChild as? Value {
path.append(String(describing: type(of: child.value)))
if let child = child.value as? Value {
return (path, child)
}
any = anyChild
any = child.value
}
if MemoryLayout<Value>.size == 0, !isUninhabitedEnum(Value.self) {
return (["\(root)"], unsafeBitCast((), to: Value.self))
Expand Down

0 comments on commit 1aa1bf7

Please sign in to comment.