Skip to content

stdlib: make RangeReplaceableCollection.SubSequence a RangeReplaceableCollection #4825

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

Conversation

gribozavr
Copy link
Contributor

This change makes RangeReplaceableCollection.SubSequence a RangeReplaceableCollection, and fixes Foundation.Data that did not conform to this requirement.

Fixes:
rdar://problem/28330668
rdar://problem/28330713

@gribozavr gribozavr force-pushed the stdlib-default-RangeReplaceableCollection.SubSequence branch from 27bde6d to 6d74d44 Compare September 16, 2016 03:20
get {
return MutableRandomAccessSlice(base: self, bounds: bounds)
return MutableRangeReplaceableRandomAccessSlice(base: self, bounds: bounds)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have an additional test case so we can verify this is the right type in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The newly-added protocol constraint ensures that the slice type conforms to RangeReplaceableCollection. I'll try to add a direct test, but I don't have access to a macOS machine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, you can use Data as Data's slice type (I was just making a minimal change). It would make sense if constructing a Data pointing to other Data's storage is O(1) (I don't know if it is).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the tests.

@gribozavr gribozavr force-pushed the stdlib-default-RangeReplaceableCollection.SubSequence branch 3 times, most recently from 560f122 to c0ee982 Compare September 17, 2016 23:16
RangeReplaceableCollection.SubSequence should be a
RangeReplaceableCollection.  Data implements RangeReplaceableCollection,
but sets SubSequence to MutableRandomAccessSlice that is not a
RangeReplaceableCollection.

This commit changes Foundation.Data.SubSequence to
MutableRangeReplaceableRandomAccessSlice.

Fixes rdar://problem/28330713.
@gribozavr gribozavr force-pushed the stdlib-default-RangeReplaceableCollection.SubSequence branch from d0da4f5 to 25378de Compare September 18, 2016 01:03
@gribozavr
Copy link
Contributor Author

@parkera Note that I'm also changing Data.Indices to be a CountableRange<Int>, because it is much faster than the default. Data does not need the full generality of the default indices type because Data.Index is just an Int.

@gribozavr
Copy link
Contributor Author

@parkera Equivalent PR for corelibs-foundation: swiftlang/swift-corelibs-foundation#646

@gribozavr
Copy link
Contributor Author

Test with: swiftlang/swift-corelibs-foundation#646

@swift-ci Please smoke test

@gribozavr
Copy link
Contributor Author

Test with: swiftlang/swift-corelibs-foundation#646

@swift-ci Please smoke test Linux platform

@dabrahams
Copy link
Contributor

@parkera OK to merge this now?

@gribozavr
Copy link
Contributor Author

Please note that this PR and swiftlang/swift-corelibs-foundation#646 should be merged simultaneously.

@parkera
Copy link
Contributor

parkera commented Sep 19, 2016

@dabrahams ok -- thanks for fixing this @gribozavr

@dabrahams dabrahams merged commit 3bf6b60 into master Sep 19, 2016
@gribozavr gribozavr deleted the stdlib-default-RangeReplaceableCollection.SubSequence branch September 19, 2016 03:58
@dabrahams dabrahams restored the stdlib-default-RangeReplaceableCollection.SubSequence branch September 29, 2016 01:23
@dabrahams dabrahams deleted the stdlib-default-RangeReplaceableCollection.SubSequence branch September 29, 2016 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants