From 053e6485ca269145f5dd5d5e2a23eef136ab96d9 Mon Sep 17 00:00:00 2001 From: Nicholas Maccharoli Date: Sun, 21 Feb 2016 22:45:14 +0900 Subject: [PATCH] Remove workaround for not being able to override a generic method in a generic subclass. Moved the implementation of the methods found in _ContiguousArrayStorage1 directly over to _ContiguousArrayStorage --- .../public/core/ContiguousArrayBuffer.swift | 48 ++++++------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/stdlib/public/core/ContiguousArrayBuffer.swift b/stdlib/public/core/ContiguousArrayBuffer.swift index 99a7efb8a6dd3..5cca42b3a3dd3 100644 --- a/stdlib/public/core/ContiguousArrayBuffer.swift +++ b/stdlib/public/core/ContiguousArrayBuffer.swift @@ -66,39 +66,8 @@ internal var _emptyArrayStorage : _EmptyArrayStorage { Builtin.addressof(&_swiftEmptyArrayStorage)) } -// FIXME: This whole class is a workaround for -// Can't override generic method in generic -// subclass. If it weren't for that bug, we'd override -// _withVerbatimBridgedUnsafeBuffer directly in -// _ContiguousArrayStorage. -class _ContiguousArrayStorage1 : _ContiguousArrayStorageBase { -#if _runtime(_ObjC) - /// If the `Element` is bridged verbatim, invoke `body` on an - /// `UnsafeBufferPointer` to the elements and return the result. - /// Otherwise, return `nil`. - final override func _withVerbatimBridgedUnsafeBuffer( - @noescape body: (UnsafeBufferPointer) throws -> R - ) rethrows -> R? { - var result: R? = nil - try self._withVerbatimBridgedUnsafeBufferImpl { - result = try body($0) - } - return result - } - - /// If `Element` is bridged verbatim, invoke `body` on an - /// `UnsafeBufferPointer` to the elements. - internal func _withVerbatimBridgedUnsafeBufferImpl( - @noescape body: (UnsafeBufferPointer) throws -> Void - ) rethrows { - _sanityCheckFailure( - "Must override _withVerbatimBridgedUnsafeBufferImpl in derived classes") - } -#endif -} - // The class that implements the storage for a ContiguousArray -final class _ContiguousArrayStorage : _ContiguousArrayStorage1 { +final class _ContiguousArrayStorage : _ContiguousArrayStorageBase { deinit { __manager._elementPointer.destroy(__manager._valuePointer.memory.count) @@ -107,9 +76,22 @@ final class _ContiguousArrayStorage : _ContiguousArrayStorage1 { } #if _runtime(_ObjC) + /// If the `Element` is bridged verbatim, invoke `body` on an + /// `UnsafeBufferPointer` to the elements and return the result. + /// Otherwise, return `nil`. + internal final override func _withVerbatimBridgedUnsafeBuffer( + @noescape body: (UnsafeBufferPointer) throws -> Element + ) rethrows -> Element? { + var result: Element? = nil + try self._withVerbatimBridgedUnsafeBufferImpl { + result = try body($0) + } + return result + } + /// If `Element` is bridged verbatim, invoke `body` on an /// `UnsafeBufferPointer` to the elements. - internal final override func _withVerbatimBridgedUnsafeBufferImpl( + internal final func _withVerbatimBridgedUnsafeBufferImpl( @noescape body: (UnsafeBufferPointer) throws -> Void ) rethrows { if _isBridgedVerbatimToObjectiveC(Element.self) {