Skip to content

Use built-in URL modifying methods instead of string concat when crea… #196

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 1 commit into from
Jun 4, 2020

Conversation

dylansturg
Copy link
Contributor

…ting paths.

The FileIterator class was using string concat to combine strings into file paths. This isn't very resilient to different types of valid input. The built-in file URL modifying methods (e.g. appendingPathComponent...) are more resilient.

This manifested as an error when trying to format a directory, where I included a trailing / in the directory path passed to swift-format. That / resulted in FileIterator working on paths that included 2 / characters. Later on, deleteLastPathComponent handles the paths with 2 / characters by appending ../. Eventually, this leads to an infinite loop of appending ../ to the search path when searching for configuration files.

I compared the performance of this implementation with the previous implementation. There wasn't a notable difference. I tested by recursively formatting the swift-protobuf repo:

  • Original: 56.7 seconds
  • Revised: 56.1 seconds

…ting paths.

The `FileIterator` class was using string concat to combine strings into file paths. This isn't very resilient to different types of valid input. The built-in file URL modifying methods (e.g. appendingPathComponent...) are more resilient.

This manifested as an error when trying to format a directory, where I included a trailing `/` in the directory path passed to swift-format. That `/` resulted in `FileIterator` working on paths that included 2 `/` characters. Later on, `deleteLastPathComponent` handles the paths with 2 `/` characters by appending `../`. Eventually, this leads to an infinite loop of appending `../` to the search path when searching for configuration files.

I compared the performance of this implementation with the previous implementation. There wasn't a notable difference. I tested by recursively formatting the swift-protobuf repo:
- Original: 56.7 seconds
- Revised: 56.1 seconds
@allevato allevato merged commit e1e5c0c into swiftlang:master Jun 4, 2020
Copy link

@hixio-mh hixio-mh left a comment

Choose a reason for hiding this comment

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

Merged pull request

@dylansturg dylansturg deleted the better_pathing branch June 5, 2020 17:06
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