mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 07:11:08 +00:00
lib/fs: Optimize Canonicalize
When pathSep is a constant, the compiler precomputes pathSep+pathSep and ".."+pathSep instead of emitting function calls to compute "//" and "../". Benchmark results in lib/osutil: name old time/op new time/op delta TraversesSymlink-8 8.86µs ± 3% 8.53µs ± 4% -3.79% (p=0.000 n=18+20) name old alloc/op new alloc/op delta TraversesSymlink-8 1.06kB ± 0% 1.06kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta TraversesSymlink-8 15.0 ± 0% 15.0 ± 0% ~ (all equal)
This commit is contained in:
parent
3e032c4da6
commit
8a1e54d58a
@ -253,7 +253,7 @@ func IsInternal(file string) bool {
|
||||
// - /foo/bar -> foo/bar
|
||||
// - / -> "."
|
||||
func Canonicalize(file string) (string, error) {
|
||||
pathSep := string(PathSeparator)
|
||||
const pathSep = string(PathSeparator)
|
||||
|
||||
if strings.HasPrefix(file, pathSep+pathSep) {
|
||||
// The relative path may pretend to be an absolute path within
|
||||
|
Loading…
Reference in New Issue
Block a user