Skip to content

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Sep 19, 2024

Improved some String+Path functions' performance with the following changes:

  • Used .utf8 where applicable (such as when searching for ascii UInt8._slash, which happens a lot)
  • Refactored some path components functions, fixed an issue where .deletingPathComponent didn't skip over consecutive trailing slashes
  • Refactored .removingDotSegments to directly modify the String buffer
  • Replaced automount prefix matching with UInt8 arrays

Non-implementation related:

  • Replaced my previous ambiguous use of a var input with utf8 to avoid confusion
  • Used UInt8._dot and ._slash instead of re-defining them in-function
  • Made state enum names more specific to avoid potential naming conflicts
  • Renamed helper functions for clarity
  • Added unit tests

Results: We generally see 2-6x speedup in the respective functions.

Old vs New String

String+Path Performance Old vs New

NSString vs String

String+Path Performance NSString vs String

@jrflat
Copy link
Contributor Author

jrflat commented Sep 19, 2024

@swift-ci please test

@jrflat jrflat merged commit 706ef7f into swiftlang:main Sep 19, 2024
3 checks passed
jrflat added a commit to jrflat/swift-foundation that referenced this pull request Oct 25, 2024
cthielen pushed a commit to cthielen/swift-foundation that referenced this pull request Nov 8, 2024
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.

2 participants