Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: Remove duplicated string copy in logger? #11515

Closed
yancl opened this issue Jul 2, 2015 · 1 comment
Closed

log: Remove duplicated string copy in logger? #11515

yancl opened this issue Jul 2, 2015 · 1 comment

Comments

@yancl
Copy link

yancl commented Jul 2, 2015

Do you think short is necessary here for 3 times string copy?,
Maybe we could just file = file[i+1:] ?
I issue this because it is in the l.mu.Lock():)

https://github.com/golang/go/blob/master/src/log/log.go#L121
    if l.flag&(Lshortfile|Llongfile) != 0 {
        if l.flag&Lshortfile != 0 {
            short := file
            for i := len(file) - 1; i > 0; i-- {
                if file[i] == '/' {
                    short = file[i+1:]
                    break
                }
            }
            file = short
        }
@bradfitz
Copy link
Contributor

bradfitz commented Jul 2, 2015

That's not a copy of the string. There's no performance problem here and the code is more readable currently than the proposed alternative.

See http://research.swtch.com/godata and http://blog.golang.org/go-slices-usage-and-internals

@bradfitz bradfitz closed this as completed Jul 2, 2015
@mikioh mikioh changed the title Remove duplicated string copy in logger? log: Remove duplicated string copy in logger? Jul 3, 2015
@golang golang locked and limited conversation to collaborators Jul 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants