mirror of
https://github.com/golang/go
synced 2024-09-05 07:54:46 +00:00
go/constant: share the empty string
This saves 11,000 allocations when loading the standard library in golang.org/x/tools/go/ssa form. Change-Id: I8aa32b0641c1a3dde29e6ee76c760006035dd56d Reviewed-on: https://go-review.googlesource.com/c/go/+/423934 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Alan Donovan <adonovan@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
c8000a18d6
commit
1f833e4a1b
|
@ -380,7 +380,14 @@ func MakeUnknown() Value { return unknownVal{} }
|
|||
func MakeBool(b bool) Value { return boolVal(b) }
|
||||
|
||||
// MakeString returns the String value for s.
|
||||
func MakeString(s string) Value { return &stringVal{s: s} }
|
||||
func MakeString(s string) Value {
|
||||
if s == "" {
|
||||
return &emptyString // common case
|
||||
}
|
||||
return &stringVal{s: s}
|
||||
}
|
||||
|
||||
var emptyString stringVal
|
||||
|
||||
// MakeInt64 returns the Int value for x.
|
||||
func MakeInt64(x int64) Value { return int64Val(x) }
|
||||
|
|
Loading…
Reference in a new issue