Optimize Path#relative_to?#15594
Conversation
|
We know all parts are well-formed and they have no separators at either end. So we could probably use a |
|
Now it makes more sense 👍 |
straight-shoota
left a comment
There was a problem hiding this comment.
Regardless of further improvements, this seems like a nice, low hanging fruit.
Of course we could do even much more by stepping through the original paths (non-normalized) directly, without iterators. Could also memcpy the trailing part of target_path.
Path#relative_to?calls#/to build up the final path successively. This is done for each path component, which means the whole method has quadratic complexity. Only a single#joinis necessary here and reduces the complexity to linear.