Optimization for String.Store("")

This commit is contained in:
Bill Fumerola
2017-05-09 15:26:45 -07:00
committed by bill fumerola
parent 0506d69f55
commit 16b44f14f0
2 changed files with 7 additions and 0 deletions

View File

@@ -45,5 +45,9 @@ func (s *String) Load() string {
// Note: Converting the string to an interface{} to store in the Value
// requires an allocation.
func (s *String) Store(str string) {
if str == "" {
s.v = Value{}
return
}
s.v.Store(str)
}

View File

@@ -40,4 +40,7 @@ func TestString(t *testing.T) {
atom = NewString("bcd")
require.Equal(t, "bcd", atom.Load(), "Expected Load to return initialized value")
atom.Store("")
require.Equal(t, "", atom.Load(), "Expected Load to return empty value")
}