Skip to content

Commit

Permalink
improved performance by avoiding unused call to os.Getwd()
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Nov 17, 2024
1 parent 2044821 commit 438af0b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions slog/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ func checkpath(file string) string {
}
}
}
cwd, _ := os.Getwd()
relfile, _ := filepath.Rel(cwd, file)
if l := len(relfile); l > 0 && l < len(privfile) {
return relfile
if filepath.IsAbs(privfile) {
cwd, _ := os.Getwd()
relfile, _ := filepath.Rel(cwd, file)
if l := len(relfile); l > 0 && l < len(privfile) {
return relfile
}
}
return privfile
}
Expand Down

0 comments on commit 438af0b

Please sign in to comment.