Skip to content

Avoid two uses of defer {} #14868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2018
Merged
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
10 changes: 6 additions & 4 deletions stdlib/public/core/ManagedBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ open class ManagedBuffer<Header, Element> {
public final func withUnsafeMutablePointers<R>(
_ body: (UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R
) rethrows -> R {
defer { _fixLifetime(self) }
return try body(headerAddress, firstElementAddress)
let r = try body(headerAddress, firstElementAddress)
_fixLifetime(self)
return r
}

/// The stored `Header` instance.
Expand Down Expand Up @@ -303,8 +304,9 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
public func withUnsafeMutablePointers<R>(
_ body: (UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R
) rethrows -> R {
defer { _fixLifetime(_nativeBuffer) }
return try body(_headerPointer, _elementPointer)
let r = try body(_headerPointer, _elementPointer)
_fixLifetime(_nativeBuffer)
return r
}

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