-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] non-mutating range subscript setter on UnsafeMutableBufferPointer #12504
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
894585f
a non-mutating range subscript setter for UnsafeMutableBufferPointer
glessard 9eeb6a0
skip assignment when source and destination are the same address
glessard 4683eff
test non-mutating and overlap behaviour of slice assignments
glessard 0fb0d51
make "subscript/defaultImplementation" test the default implementation
glessard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -580,21 +580,17 @@ CollectionTypeTests.test("subscript(_: Range<Index>)/writeback") { | |
CollectionTypeTests.test("subscript(_: Range<Index>)/defaultImplementation/sliceTooLarge") | ||
.crashOutputMatches("Cannot replace a slice of a MutableCollection with a slice of a larger size") | ||
.code { | ||
var x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
var x = Slice(base: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], bounds: 0..<10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed from |
||
expectCrashLater() | ||
x.withUnsafeMutableBufferPointer { buffer in | ||
buffer[2..<4] = buffer[4..<8] | ||
} | ||
x[2..<4] = x[4..<8] | ||
} | ||
|
||
CollectionTypeTests.test("subscript(_: Range<Index>)/defaultImplementation/sliceTooSmall") | ||
.crashOutputMatches("Cannot replace a slice of a MutableCollection with a slice of a smaller size") | ||
.code { | ||
var x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
var x = Slice(base: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], bounds: 0..<10) | ||
expectCrashLater() | ||
x.withUnsafeMutableBufferPointer { buffer in | ||
buffer[2..<6] = buffer[6..<8] | ||
} | ||
x[2..<6] = x[6..<8] | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one should be a full
_precondition
(similar to the one found in_writeBackMutableSlice
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The analog line in UnsafeRawBufferPointer uses a
_debugPrecondition
: https://github.com/apple/swift/blob/ffd34239a1b6f046346769a55ae8e717f64e13eb/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb#L468Is there a reason to make it stronger in the typed buffers, or should it be a
_precondition
in both places?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reasoning behind
_debugPrecondition
is that this is already anUnsafe
type and being at the the lowest level of abstraction will be used in performance critical code.