Skip to content

Commit dfbc6ed

Browse files
committed
encoding/json: use reflect.Value.IsZero
IsZero does the same thing, using this rather than writing it again.
1 parent 14c347f commit dfbc6ed

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/encoding/json/encode.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,12 @@ func isEmptyValue(v reflect.Value) bool {
307307
switch v.Kind() {
308308
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
309309
return v.Len() == 0
310-
case reflect.Bool:
311-
return v.Bool() == false
312-
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
313-
return v.Int() == 0
314-
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
315-
return v.Uint() == 0
316-
case reflect.Float32, reflect.Float64:
317-
return v.Float() == 0
318-
case reflect.Interface, reflect.Pointer:
319-
return v.IsNil()
310+
case reflect.Bool,
311+
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
312+
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
313+
reflect.Float32, reflect.Float64,
314+
reflect.Interface, reflect.Pointer:
315+
return v.IsZero()
320316
}
321317
return false
322318
}

0 commit comments

Comments
 (0)