Skip to content
Closed
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
1 change: 1 addition & 0 deletions stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set(SWIFTLIB_ESSENTIAL
Comparable.swift
CompilerProtocols.swift
ContiguousArray.swift
ContiguousCollection.swift
ContiguouslyStored.swift
ClosedRange.swift
ContiguousArrayBuffer.swift
Expand Down
74 changes: 74 additions & 0 deletions stdlib/public/core/ContiguousCollection.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// A collection that supports access to its underlying contiguous storage.
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)

OSX => macOS (11 times) and in same order as rest of stdlib, for easier find and replace.

public protocol ContiguousCollection: Collection
where SubSequence: ContiguousCollection {
/// Calls a closure with a pointer to the array's contiguous storage.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Calls a closure with a pointer to the array's contiguous storage.
/// Calls a closure with a pointer to contiguous storage.

Remove: the array's (also in the proposal).

func withUnsafeBufferPointer<R>(
_ body: (UnsafeBufferPointer<Element>) throws -> R
) rethrows -> R
}

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
public extension ContiguousCollection {
@inlinable
func withUnsafeBufferPointer<R>(
_ body: (UnsafeBufferPointer<Element>) throws -> R
) rethrows -> R {
return try withContiguousStorageIfAvailable(body)!
}
}

/// A collection that supports mutable access to its underlying contiguous
/// storage.
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
public protocol MutableContiguousCollection: ContiguousCollection, MutableCollection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap to 80 characters?

where SubSequence: MutableContiguousCollection {
/// Calls the given closure with a pointer to the array's mutable contiguous
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Calls the given closure with a pointer to the array's mutable contiguous
/// Calls the given closure with a pointer to mutable contiguous

Remove: the array's (also in the proposal).

/// storage.
mutating func withUnsafeMutableBufferPointer<R>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R
}

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension MutableContiguousCollection {
@inlinable
public mutating func withUnsafeMutableBufferPointer<R>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R {
return try withContiguousMutableStorageIfAvailable(body)!
}
}

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension Array: MutableContiguousCollection { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension ContiguousArray: MutableContiguousCollection { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension ArraySlice: MutableContiguousCollection { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension UnsafeBufferPointer: ContiguousCollection { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension UnsafeMutableBufferPointer: MutableContiguousCollection { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension Slice: ContiguousCollection where Base: ContiguousCollection { }

@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
extension Slice: MutableContiguousCollection where Base: MutableContiguousCollection { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap to 80 characters?

1 change: 1 addition & 0 deletions stdlib/public/core/GroupInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"CocoaArray.swift",
"ContiguousArray.swift",
"ContiguousArrayBuffer.swift",
"ContiguousCollection.swift",
"ContiguouslyStored.swift",
"FixedArray.swift",
"SliceBuffer.swift",
Expand Down