]> Cypherpunks.ru repositories - gostls13.git/commitdiff
encoding/json: use reflect.Value.IsZero
authorandig <cpuidle@gmx.de>
Sat, 14 Oct 2023 09:32:20 +0000 (09:32 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 18 Oct 2023 20:00:40 +0000 (20:00 +0000)
IsZero does the same thing, using this rather than writing it again.

Follow-up to https://github.com/golang/go/pull/63519

Change-Id: I93768874052935dd7cb58804f22748091bcc3ef7
GitHub-Last-Rev: dfbc6ed635125535a73fe509716e0df31cc8f7b0
GitHub-Pull-Request: golang/go#63540
Reviewed-on: https://go-review.googlesource.com/c/go/+/535415
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/encoding/json/encode.go

index 9d6d7adcef753320c274a668811b1ef0a5300bb2..d6f6900dc969ef04dda02a9fbef51a1066be3086 100644 (file)
@@ -307,16 +307,12 @@ func isEmptyValue(v reflect.Value) bool {
        switch v.Kind() {
        case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
                return v.Len() == 0
-       case reflect.Bool:
-               return v.Bool() == false
-       case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
-               return v.Int() == 0
-       case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
-               return v.Uint() == 0
-       case reflect.Float32, reflect.Float64:
-               return v.Float() == 0
-       case reflect.Interface, reflect.Pointer:
-               return v.IsNil()
+       case reflect.Bool,
+               reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
+               reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
+               reflect.Float32, reflect.Float64,
+               reflect.Interface, reflect.Pointer:
+               return v.IsZero()
        }
        return false
 }