Optimize path::remove_dots
authorReid Kleckner <rnk@google.com>
Sun, 3 May 2020 13:26:12 +0000 (06:26 -0700)
committerReid Kleckner <rnk@google.com>
Sun, 3 May 2020 14:58:05 +0000 (07:58 -0700)
commit53913a65b408ade2956061b4c0aaed6bba907403
tree8e0422646ec5a727a31bdaee97cc563bfa95740f
parent9b7f6146bd4734f4ded2c3e572261961a43d3ef2
Optimize path::remove_dots

LLD calls this on every source file string in every object file when
writing PDBs, so it is somewhat hot.

Avoid rewriting paths that do not contain path traversal components
(./..). Use find_first_not_of(separators) directly instead of using the
path iterators. The path component iterators appear to be slow, and
directly searching for slashes makes it easier to find double separators
that need to be canonicalized.

I discovered that the VFS relies on remote_dots to not canonicalize
early slashes (/foo or C:/foo) on Windows, so I had to leave that
behavior behind with unit tests for it. This is undesirable, but I claim
that my change is NFC.
llvm/lib/Support/Path.cpp
llvm/lib/Support/Windows/Path.inc
llvm/unittests/Support/Path.cpp