-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
Optimize PathBuf::push for verbatim paths
#162490
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
ChrisDenton marked this conversation as resolved.
Member
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. I think the test coverage is missing cases starting with |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1759,13 +1759,60 @@ pub fn test_push() { | |
|
|
||
| tp!(r"\\?\C:\bar", "../foo", r"\\?\C:\foo"); | ||
| tp!(r"\\?\C:\bar", "../../foo", r"\\?\C:\foo"); | ||
| tp!(r"\\?\C:\foo\bar", "../baz", r"\\?\C:\foo\baz"); | ||
| tp!(r"\\?\C:\foo\bar\", "../baz", r"\\?\C:\foo\baz"); | ||
| tp!(r"\\?\C:\foo\bar\", "..", r"\\?\C:\foo"); | ||
|
Comment on lines
+1762
to
+1764
Member
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. What about pushing What about the UNC share case? What if you push
Member
Author
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.
Aren't some these cases not handled above and below? I can add some more though.
Hm, looking through the tests it seems we don't have as good coverage of
Member
Author
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. Done. There were basically two cases where the old and new version differed:
In any case I've split the commits into two so you can see what changed more easily. |
||
| tp!(r"\\?\C:\foo", "..", r"\\?\C:\"); | ||
| tp!(r"\\?\C:\", "..", r"\\?\C:\"); | ||
| tp!(r"\\?\C:\foo\..", "..", r"\\?\C:\foo\.."); | ||
| tp!(r"\\?\C:\", "../foo", r"\\?\C:\foo"); | ||
| tp!(r"\\?\C:", r"D:\foo/./", r"D:\foo/./"); | ||
| tp!(r"\\?\C:", r"\\?\D:\foo\.\", r"\\?\D:\foo\.\"); | ||
| tp!(r"\\?\C:", r"\..", r"\\?\C:\"); | ||
| tp!(r"\\?\C:", r"\\foo\\\..", r"\\?\C:\"); | ||
| tp!(r"\\?\C:", r"foo\foo\..\..", r"\\?\C:"); | ||
| tp!(r"\\?\C:\foo\..\..\bar", r"..\..\..\", r"\\?\C:\foo\..\.."); | ||
| tp!(r"\\?\C:\foo\..", r"..\bar", r"\\?\C:\foo\..\bar"); | ||
| tp!(r"\\?\C:\foo\..\..", r"..\bar", r"\\?\C:\foo\..\..\bar"); | ||
| tp!(r"\\?\C:\foo\..", r"..\..\..\bar", r"\\?\C:\foo\..\bar"); | ||
| tp!(r"\\?\C:\foo\..\", r"..\..\..\bar", r"\\?\C:\foo\..\bar"); | ||
| tp!(r"\\?\C:\foo\..\\", r"..", r"\\?\C:\foo\.."); | ||
| tp!(r"\\?\C:\foo\.", r"..", r"\\?\C:\foo\."); | ||
| tp!(r"\\?\C:\foo\..\", r"..", r"\\?\C:\foo\.."); | ||
| tp!(r"\\?\C:\foo\\\\bar", r"..", r"\\?\C:\foo"); | ||
| tp!(r"\\?\C:\foo\", r".", r"\\?\C:\foo"); | ||
| tp!(r"\\?\C:\foo\\", r"bar", r"\\?\C:\foo\bar"); | ||
| tp!(r"\\?\C:\foo\\\\bar", r"baz", r"\\?\C:\foo\bar\baz"); | ||
| tp!(r"\\?\A:\x\y", "/foo", r"\\?\A:\foo"); | ||
| tp!(r"\\?\A:", r"..\foo\.", r"\\?\A:\foo"); | ||
| tp!(r"\\?\A:\x\y", r".\foo\.", r"\\?\A:\x\y\foo"); | ||
| tp!(r"\\?\A:\x\y", r"", r"\\?\A:\x\y\"); | ||
|
|
||
| tp!(r"\\?\UNC\server\share\foo", r"..", r"\\?\UNC\server\share\"); | ||
| tp!(r"\\?\UNC\server\share\", r"..", r"\\?\UNC\server\share\"); | ||
| tp!(r"\\?\UNC\server\share\foo\bar", "../baz", r"\\?\UNC\server\share\foo\baz"); | ||
| tp!(r"\\?\UNC\server\share\foo\bar\", "../baz", r"\\?\UNC\server\share\foo\baz"); | ||
| tp!(r"\\?\UNC\server\share\foo\bar\", "..", r"\\?\UNC\server\share\foo"); | ||
| tp!(r"\\?\UNC\server\share\foo", "..", r"\\?\UNC\server\share\"); | ||
| tp!(r"\\?\UNC\server\share\", "..", r"\\?\UNC\server\share\"); | ||
| tp!(r"\\?\UNC\server\share\foo\..", "..", r"\\?\UNC\server\share\foo\.."); | ||
| tp!(r"\\?\UNC\server\share\", "../foo", r"\\?\UNC\server\share\foo"); | ||
| tp!(r"\\?\UNC\server\share", r"D:\foo/./", r"D:\foo/./"); | ||
| tp!(r"\\?\UNC\server\share", r"\\?\D:\foo\.\", r"\\?\D:\foo\.\"); | ||
| tp!(r"\\?\UNC\server\share", r"\..", r"\\?\UNC\server\share\"); | ||
|
|
||
| tp!(r"\\?\PIPE\foo", r"\", r"\\?\PIPE\"); | ||
|
|
||
| // Empty verbatim prefix. | ||
| tp!(r"\\?\\foo", r"..", r"\\?\\"); | ||
| tp!(r"\\?\\foo", r"../..", r"\\?\\"); | ||
| tp!(r"\\?\\foo", r"\", r"\\?\\"); | ||
| tp!(r"\\?\\foo", r"../bar", r"\\?\\bar"); | ||
|
|
||
| tp!(r"\\?\C:\foo\foo\/", r"foo", r"\\?\C:\foo\foo\/\foo"); | ||
| tp!(r"\\?\/", r"/", r"\\?\/\"); | ||
| tp!(r"\\?\foo/", r"/", r"\\?\foo/\"); | ||
| tp!(r"\\?\", r"foo\foo\..\..", r"\\?\"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
We're still changing the behavior when there are internal double slashes. For example:
PathBuf::from(r"\\?\C:\foo\\").push("bar")PathBuf::from(r"\\?\C:\foo\\\\bar").push("baz")Uh oh!
There was an error while loading. Please reload this page.
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've added back iterating over the full base path to fixup consecutive
\but without allocating, which does require a way to get a mutable slice from anOsStr.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 you can use
mem::takeon thePathBuf, then convert it to a vector, then useretain, then convert it back.