Optimization for String.Store("")
This commit is contained in:
committed by
bill fumerola
parent
0506d69f55
commit
16b44f14f0
@@ -45,5 +45,9 @@ func (s *String) Load() string {
|
|||||||
// Note: Converting the string to an interface{} to store in the Value
|
// Note: Converting the string to an interface{} to store in the Value
|
||||||
// requires an allocation.
|
// requires an allocation.
|
||||||
func (s *String) Store(str string) {
|
func (s *String) Store(str string) {
|
||||||
|
if str == "" {
|
||||||
|
s.v = Value{}
|
||||||
|
return
|
||||||
|
}
|
||||||
s.v.Store(str)
|
s.v.Store(str)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,4 +40,7 @@ func TestString(t *testing.T) {
|
|||||||
|
|
||||||
atom = NewString("bcd")
|
atom = NewString("bcd")
|
||||||
require.Equal(t, "bcd", atom.Load(), "Expected Load to return initialized value")
|
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")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user