Skip to content

Commit 619387f

Browse files
authored
Merge pull request #14868 from apple/kill-2-defers
2 parents cbeacfd + 6a3a91d commit 619387f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

stdlib/public/core/ManagedBuffer.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ open class ManagedBuffer<Header, Element> {
118118
public final func withUnsafeMutablePointers<R>(
119119
_ body: (UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R
120120
) rethrows -> R {
121-
defer { _fixLifetime(self) }
122-
return try body(headerAddress, firstElementAddress)
121+
let r = try body(headerAddress, firstElementAddress)
122+
_fixLifetime(self)
123+
return r
123124
}
124125

125126
/// The stored `Header` instance.
@@ -303,8 +304,9 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
303304
public func withUnsafeMutablePointers<R>(
304305
_ body: (UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R
305306
) rethrows -> R {
306-
defer { _fixLifetime(_nativeBuffer) }
307-
return try body(_headerPointer, _elementPointer)
307+
let r = try body(_headerPointer, _elementPointer)
308+
_fixLifetime(_nativeBuffer)
309+
return r
308310
}
309311

310312
/// Returns `true` iff `self` holds the only strong reference to its buffer.

0 commit comments

Comments
 (0)