len(cfgData) == 0
with cfgData == ""
129 if err != nil {
130 return err
131 }
132 if len(cfgData) == 0 {133 return nil
134 }
135 newCfg := &shuffleHotRegionSchedulerConfig{}
len(cfgData) == 0
with cfgData == ""
167 if err != nil {
168 return err
169 }
170 if len(cfgData) == 0 {171 return nil
172 }
173 newCfg := &grantHotRegionSchedulerConfig{}
len(cfgData) == 0
with cfgData == ""
273 if err != nil {
274 return err
275 }
276 if len(cfgData) == 0 { 277 return nil
278 }
279 newCfg := &hotRegionSchedulerConfig{}
len(s) == 0
with s == ""
80
81// StringToBytes converts string to slice of bytes without copy.
82func StringToBytes(s string) []byte {
83 if len(s) == 0 {84 return nil
85 }
86 return unsafe.Slice(unsafe.StringData(s), len(s))
len(*v) == 0
with *v == ""
121
122// AdjustString adjusts the value of a string variable.
123func AdjustString(v *string, defValue string) {
124 if len(*v) == 0 {125 *v = defValue
126 }
127}
It is not recommended to use len
for empty string test.
A string can be tested for its emptiness either by treating it as a slice and calculating the length of the slice, or by treating it as a string and directly comparing the value. While both produce identical code when compiled, it makes more sense to treat a string as itself, than a slice, for the sake of comparison of values.
len(s) == 0
s == ""
The recommended practice is considered more idiomatic in Go.