-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: use a fastest implementation of for filepath.Abs instead
- Loading branch information
Showing
8 changed files
with
54 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package frankenphp | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// FastAbs is an optimized version of filepath.Abs for Unix systems, | ||
// since we don't expect the working directory to ever change once | ||
// Caddy is running. Avoid the os.Getwd() syscall overhead. | ||
// | ||
// This function is INTERNAL and must not be used outside of this package. | ||
func FastAbs(path string) (string, error) { | ||
if filepath.IsAbs(path) { | ||
return filepath.Clean(path), nil | ||
} | ||
|
||
if wderr != nil { | ||
return "", wderr | ||
} | ||
|
||
return filepath.Join(wd, path), nil | ||
} | ||
|
||
var wd, wderr = os.Getwd() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package frankenphp | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
// FastAbs can't be optimized on Windows because the | ||
// syscall.FullPath function takes an input. | ||
// | ||
// This function is INTERNAL and must not be used outside of this package. | ||
func FastAbs(path string) (string, error) { | ||
return filepath.Abs(path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters