Skip to content

[5.0] Assorted String bridging improvements #20899

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

Closed

Conversation

Catfish-Man
Copy link
Contributor

Explanation:
• Convert _AbstractStringStorage to a protocol, and the free functions used to deduplicate implementations to extensions on that protocol.
• Move 'start' into the abstract type and use that to simplify some code
• Move the ASCII fast path for length into UTF16View.
• Add a weirder but faster way to check which (if any) of our NSString subclasses a given object is, and adopt it

Scope: This changes most operations on Swift Strings which are bridged into ObjC, but in relatively minor ways. This is a performance improvement, but is primarily important for Swift 5.0 because it will cause merge conflicts repeatedly if we don't have it.

Risk: Low-Medium. The main risk would be if someone is somehow relying on KVO subclassing of bridged Swift Strings, but since KVO doesn't actually work on NSStrings,

Testing: Passed regression tests, and the perf test suite exercises these operations over the bridge as well.

Reviewed by: @milseman

@Catfish-Man Catfish-Man requested a review from a team as a code owner November 30, 2018 02:41
@milseman
Copy link
Member

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - dc6a85070c35aef89ef58d05136a602a42d794a3

@airspeedswift
Copy link
Member

So #20900 supersedes this, right?

@milseman
Copy link
Member

That cherry-picks this, which would otherwise conflict after either is merged. I don't care how you prefer to manage it, if you merge this than a rebase would drop it from the other PR.

The test failure looks legit:


/Users/buildnode/jenkins/workspace/swift-PR-osx/branch-swift-5.0-branch/swift/stdlib/public/core/StringStorage.swift:191:25: error: property does not override any property from its superclass
09:06:32   override internal var count: Int {
09:06:32   ~~~~~~~~              ^
09:06:32 /Users/buildnode/jenkins/workspace/swift-PR-osx/branch-swift-5.0-branch/swift/stdlib/public/core/StringStorage.swift:83:16: warning: result of call to 'initialize(from:)' is unused
09:06:32         buffer.initialize(from: UnsafeBufferPointer(start: start, count: count))
09:06:32                ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
09:06:32 /Users/buildnode/jenkins/workspace/swift-PR-osx/branch-swift-5.0-branch/swift/stdlib/public/core/StringStorage.swift:135:15: error: pattern cannot match values of type '_KnownCocoaString'
09:06:32         case .tagged:
09:06:32              ~^~~~~~

@Catfish-Man, is there more to cherry-pick here? Can you diff the file vs master and make sure we get everything?

@Catfish-Man
Copy link
Contributor Author

Dangit, I thought I included the fix for that. Will deal with that shortly.

@milseman
Copy link
Member

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - dc6a85070c35aef89ef58d05136a602a42d794a3

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - dc6a85070c35aef89ef58d05136a602a42d794a3

• Convert _AbstractStringStorage to a protocol, and the free functions used to deduplicate implementations to extensions on that protocol.
• Move 'start' into the abstract type and use that to simplify some code
• Move the ASCII fast path for length into UTF16View.
• Add a weirder but faster way to check which (if any) of our NSString subclasses a given object is, and adopt it

(cherry picked from commit 8b57921)
@Catfish-Man
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 98514e1a333ba8ffdddaf3b3cb432c61e7681ab6

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 98514e1a333ba8ffdddaf3b3cb432c61e7681ab6

@airspeedswift
Copy link
Member

Closing as superseded by #20900

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.

4 participants