1
0
mirror of https://github.com/golang/go synced 2024-11-19 07:44:49 -07:00

cmd/compile: convert fmt.Sprintf to concatenation

There are plenty more, but these cover most of
the trivial cases, and all the cases that
showed up in profiling.

name       old time/op     new time/op     delta
Template       331ms ± 3%      327ms ± 6%    ~           (p=0.143 n=10+10)
Unicode        183ms ± 4%      180ms ± 2%    ~             (p=0.114 n=9+8)
GoTypes        1.12s ± 4%      1.07s ± 1%  -4.34%         (p=0.000 n=10+9)
Compiler       5.16s ± 2%      5.04s ± 2%  -2.24%         (p=0.001 n=10+9)
MakeBash       41.7s ± 2%      42.3s ± 1%  +1.51%        (p=0.000 n=10+10)

name       old alloc/op    new alloc/op    delta
Template      63.4MB ± 0%     63.1MB ± 0%  -0.42%        (p=0.000 n=10+10)
Unicode       43.2MB ± 0%     43.1MB ± 0%  -0.22%         (p=0.000 n=9+10)
GoTypes        220MB ± 0%      219MB ± 0%  -0.57%         (p=0.000 n=8+10)
Compiler       978MB ± 0%      975MB ± 0%  -0.30%        (p=0.000 n=10+10)

name       old allocs/op   new allocs/op   delta
Template        702k ± 0%       686k ± 0%  -2.35%        (p=0.000 n=10+10)
Unicode         548k ± 0%       542k ± 0%  -1.09%        (p=0.000 n=10+10)
GoTypes        2.17M ± 0%      2.09M ± 0%  -3.61%        (p=0.000 n=10+10)
Compiler       9.33M ± 0%      9.15M ± 0%  -1.93%        (p=0.000 n=10+10)

Change-Id: I3a3d7f2d56876427b04cfedc7302d7f496d5bb65
Reviewed-on: https://go-review.googlesource.com/20904
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2016-03-19 16:34:48 -07:00
parent 8dc04cbedc
commit ad4c55c076

View File

@ -445,16 +445,16 @@ func symfmt(s *Sym, flag FmtFlag) string {
if s.Pkg.Name != "" && numImport[s.Pkg.Name] > 1 {
return fmt.Sprintf("%q.%s", s.Pkg.Path, s.Name)
}
return fmt.Sprintf("%s.%s", s.Pkg.Name, s.Name)
return s.Pkg.Name + "." + s.Name
case FDbg:
return fmt.Sprintf("%s.%s", s.Pkg.Name, s.Name)
return s.Pkg.Name + "." + s.Name
case FTypeId:
if flag&FmtUnsigned != 0 {
return fmt.Sprintf("%s.%s", s.Pkg.Name, s.Name) // dcommontype, typehash
return s.Pkg.Name + "." + s.Name // dcommontype, typehash
}
return fmt.Sprintf("%s.%s", s.Pkg.Prefix, s.Name) // (methodsym), typesym, weaksym
return s.Pkg.Prefix + "." + s.Name // (methodsym), typesym, weaksym
case FExp:
if s.Name != "" && s.Name[0] == '.' {
@ -569,35 +569,35 @@ func typefmt(t *Type, flag FmtFlag) string {
switch t.Etype {
case TPTR32, TPTR64:
if fmtmode == FTypeId && (flag&FmtShort != 0) {
return fmt.Sprintf("*%v", Tconv(t.Type, FmtShort))
return "*" + Tconv(t.Type, FmtShort)
}
return fmt.Sprintf("*%v", t.Type)
return "*" + t.Type.String()
case TARRAY:
if t.Bound >= 0 {
return fmt.Sprintf("[%d]%v", t.Bound, t.Type)
}
if t.Bound == -100 {
return fmt.Sprintf("[...]%v", t.Type)
return "[...]" + t.Type.String()
}
return fmt.Sprintf("[]%v", t.Type)
return "[]" + t.Type.String()
case TCHAN:
switch t.Chan {
case Crecv:
return fmt.Sprintf("<-chan %v", t.Type)
return "<-chan " + t.Type.String()
case Csend:
return fmt.Sprintf("chan<- %v", t.Type)
return "chan<- " + t.Type.String()
}
if t.Type != nil && t.Type.Etype == TCHAN && t.Type.Sym == nil && t.Type.Chan == Crecv {
return fmt.Sprintf("chan (%v)", t.Type)
return "chan (" + t.Type.String() + ")"
}
return fmt.Sprintf("chan %v", t.Type)
return "chan " + t.Type.String()
case TMAP:
return fmt.Sprintf("map[%v]%v", t.Key(), t.Type)
return "map[" + t.Key().String() + "]" + t.Type.String()
case TINTER:
var buf bytes.Buffer
@ -662,15 +662,15 @@ func typefmt(t *Type, flag FmtFlag) string {
// Format the bucket struct for map[x]y as map.bucket[x]y.
// This avoids a recursive print that generates very long names.
if t.Map.Bucket == t {
return fmt.Sprintf("map.bucket[%v]%v", t.Map.Key(), t.Map.Type)
return "map.bucket[" + t.Map.Key().String() + "]" + t.Map.Type.String()
}
if t.Map.Hmap == t {
return fmt.Sprintf("map.hdr[%v]%v", t.Map.Key(), t.Map.Type)
return "map.hdr[" + t.Map.Key().String() + "]" + t.Map.Type.String()
}
if t.Map.Hiter == t {
return fmt.Sprintf("map.iter[%v]%v", t.Map.Key(), t.Map.Type)
return "map.iter[" + t.Map.Key().String() + "]" + t.Map.Type.String()
}
Yyerror("unknown internal map type")
@ -708,7 +708,7 @@ func typefmt(t *Type, flag FmtFlag) string {
case TFORW:
if t.Sym != nil {
return fmt.Sprintf("undefined %v", t.Sym)
return "undefined " + t.Sym.String()
}
return "undefined"