Skip to content

Commit

Permalink
Remove UInt64
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Jan 19, 2024
1 parent 79a0392 commit 312f234
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 37 deletions.
2 changes: 0 additions & 2 deletions log/internal/writer_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func (l *writerLogger) appendValue(v log.Value) {
l.write(v.String())
case log.KindInt64:
l.write(strconv.FormatInt(v.Int64(), 10)) // strconv.FormatInt allocates memory.
case log.KindUint64:
l.write(strconv.FormatInt(int64(v.Uint64()), 10)) // strconv.FormatInt allocates memory.
case log.KindFloat64:
l.write(strconv.FormatFloat(v.Float64(), 'g', -1, 64)) // strconv.FormatFloat allocates memory.
case log.KindBool:
Expand Down
29 changes: 2 additions & 27 deletions log/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// The zero Value corresponds to nil.
type Value struct {
_ [0]func() // disallow ==
// num holds the value for Kinds: Int64, Uint64, Float64, and Bool,
// num holds the value for Kinds: Int64, Float64, and Bool,
// the length for String, Bytes, Group.
num uint64
// If any is of type Kind, then the value is in num as described above.
Expand All @@ -43,7 +43,6 @@ const (
KindFloat64
KindInt64
KindString
KindUint64
KindBytes
KindGroup
)
Expand All @@ -54,7 +53,6 @@ var kindStrings = []string{
"Float64",
"Int64",
"String",
"Uint64",
"Bytes",
"Group",
}
Expand Down Expand Up @@ -99,11 +97,6 @@ func Int64Value(v int64) Value {
return Value{num: uint64(v), any: KindInt64}
}

// Uint64Value returns a [Value] for a uint64.
func Uint64Value(v uint64) Value {
return Value{num: v, any: KindUint64}
}

// Float64Value returns a [Value] for a floating-point number.
func Float64Value(v float64) Value {
return Value{num: math.Float64bits(v), any: KindFloat64}
Expand Down Expand Up @@ -160,8 +153,6 @@ func (v Value) Any() any {
return v.group()
case KindInt64:
return int64(v.num)
case KindUint64:
return v.num
case KindFloat64:
return v.float()
case KindString:
Expand Down Expand Up @@ -201,15 +192,6 @@ func (v Value) Int64() int64 {
return int64(v.num)
}

// Uint64 returns v's value as a uint64. It panics
// if v is not an unsigned integer.
func (v Value) Uint64() uint64 {
if g, w := v.Kind(), KindUint64; g != w {
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
}
return v.num
}

// Bool returns v's value as a bool. It panics
// if v is not a bool.
func (v Value) Bool() bool {
Expand Down Expand Up @@ -276,7 +258,7 @@ func (v Value) Equal(w Value) bool {
return false
}
switch k1 {
case KindInt64, KindUint64, KindBool:
case KindInt64, KindBool:
return v.num == w.num
case KindString:
return v.str() == w.str()
Expand Down Expand Up @@ -312,8 +294,6 @@ func (v Value) append(dst []byte) []byte {
return append(dst, v.str()...)
case KindInt64:
return strconv.AppendInt(dst, int64(v.num), 10)
case KindUint64:
return strconv.AppendUint(dst, v.num, 10)
case KindFloat64:
return strconv.AppendFloat(dst, v.float(), 'g', -1, 64)
case KindBool:
Expand Down Expand Up @@ -351,11 +331,6 @@ func Int(key string, value int) KeyValue {
return Int64(key, int64(value))
}

// Uint64 returns an KeyValue for a uint64.
func Uint64(key string, v uint64) KeyValue {
return KeyValue{key, Uint64Value(v)}
}

// Float64 returns an KeyValue for a floating-point number.
func Float64(key string, v float64) KeyValue {
return KeyValue{key, Float64Value(v)}
Expand Down
8 changes: 0 additions & 8 deletions log/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestValueString(t *testing.T) {
want string
}{
{Int64Value(-3), "-3"},
{Uint64Value(1), "1"},
{Float64Value(.15), "0.15"},
{BoolValue(true), "true"},
{StringValue("foo"), "foo"},
Expand All @@ -67,7 +66,6 @@ func TestValueNoAlloc(t *testing.T) {
// Assign values just to make sure the compiler doesn't optimize away the statements.
var (
i int64
u uint64
f float64
b bool
by []byte
Expand All @@ -76,15 +74,13 @@ func TestValueNoAlloc(t *testing.T) {
bytes := []byte{1, 3, 4}
a := int(testing.AllocsPerRun(5, func() {
i = Int64Value(1).Int64()
u = Uint64Value(1).Uint64()
f = Float64Value(1).Float64()
b = BoolValue(true).Bool()
by = BytesValue(bytes).Bytes()
s = StringValue("foo").String()
}))
assert.Zero(t, a)
_ = i
_ = u
_ = f
_ = b
_ = by
Expand All @@ -95,7 +91,6 @@ func TestKeyValueNoAlloc(t *testing.T) {
// Assign values just to make sure the compiler doesn't optimize away the statements.
var (
i int64
u uint64
f float64
b bool
by []byte
Expand All @@ -104,15 +99,13 @@ func TestKeyValueNoAlloc(t *testing.T) {
bytes := []byte{1, 3, 4}
a := int(testing.AllocsPerRun(5, func() {
i = Int64("key", 1).Value.Int64()
u = Uint64("key", 1).Value.Uint64()
f = Float64("key", 1).Value.Float64()
b = Bool("key", true).Value.Bool()
by = Bytes("key", bytes).Value.Bytes()
s = String("key", "foo").Value.String()
}))
assert.Zero(t, a)
_ = i
_ = u
_ = f
_ = b
_ = by
Expand All @@ -127,7 +120,6 @@ func TestValueAny(t *testing.T) {
{"s", StringValue("s")},
{true, BoolValue(true)},
{int64(4), IntValue(4)},
{uint64(2), Uint64Value(2)},
{int64(11), Int64Value(11)},
{1.5, Float64Value(1.5)},
{[]byte{1, 2, 3}, BytesValue([]byte{1, 2, 3})},
Expand Down

0 comments on commit 312f234

Please sign in to comment.