diff --git a/container/gtype/gtype.go b/container/gtype/gtype.go index b43e7f7d6..d6711f2a1 100644 --- a/container/gtype/gtype.go +++ b/container/gtype/gtype.go @@ -4,14 +4,11 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -// Package gtype provides kinds of high performance and concurrent-safe basic variable types. +// Package gtype provides high performance and concurrent-safe basic variable types. package gtype -// Type is alias of Interface. -type Type = Interface - // New is alias of NewInterface. // See NewInterface. -func New(value ...interface{}) *Type { +func New(value ...interface{}) *Interface { return NewInterface(value...) } diff --git a/container/gtype/gtype_bool.go b/container/gtype/gtype_bool.go index 4b7e45909..e24b5cd21 100644 --- a/container/gtype/gtype_bool.go +++ b/container/gtype/gtype_bool.go @@ -51,7 +51,7 @@ func (v *Bool) Set(value bool) (old bool) { return } -// Val atomically loads and returns t.valueue. +// Val atomically loads and returns t.value. func (v *Bool) Val() bool { return atomic.LoadInt32(&v.value) > 0 } diff --git a/container/gtype/gtype_float32.go b/container/gtype/gtype_float32.go index 7da59ce87..364a979f0 100644 --- a/container/gtype/gtype_float32.go +++ b/container/gtype/gtype_float32.go @@ -11,7 +11,6 @@ import ( "math" "strconv" "sync/atomic" - "unsafe" ) // Float32 is a struct for concurrent-safe operation for type float32. @@ -51,7 +50,7 @@ func (v *Float32) Add(delta float32) (new float32) { old := math.Float32frombits(v.value) new = old + delta if atomic.CompareAndSwapUint32( - (*uint32)(unsafe.Pointer(&v.value)), + &v.value, math.Float32bits(old), math.Float32bits(new), ) { diff --git a/container/gtype/gtype_float64.go b/container/gtype/gtype_float64.go index 340bdef00..dcf68aa7d 100644 --- a/container/gtype/gtype_float64.go +++ b/container/gtype/gtype_float64.go @@ -11,7 +11,6 @@ import ( "math" "strconv" "sync/atomic" - "unsafe" ) // Float64 is a struct for concurrent-safe operation for type float64. @@ -51,7 +50,7 @@ func (v *Float64) Add(delta float64) (new float64) { old := math.Float64frombits(v.value) new = old + delta if atomic.CompareAndSwapUint64( - (*uint64)(unsafe.Pointer(&v.value)), + &v.value, math.Float64bits(old), math.Float64bits(new), ) { diff --git a/container/gtype/gtype_z_unit_bytes_test.go b/container/gtype/gtype_z_unit_bytes_test.go index 49145d290..468673eb1 100644 --- a/container/gtype/gtype_z_unit_bytes_test.go +++ b/container/gtype/gtype_z_unit_bytes_test.go @@ -22,7 +22,7 @@ func Test_Bytes(t *testing.T) { t.AssertEQ(iClone.Set([]byte("123")), []byte("abc")) t.AssertEQ(iClone.Val(), []byte("123")) - //空参测试 + // 空参测试 i1 := gtype.NewBytes() t.AssertEQ(i1.Val(), nil) }) diff --git a/util/grand/grand.go b/util/grand/grand.go index 63a71618d..77478cee4 100644 --- a/util/grand/grand.go +++ b/util/grand/grand.go @@ -10,7 +10,6 @@ package grand import ( "encoding/binary" "time" - "unsafe" ) var ( @@ -20,7 +19,7 @@ var ( characters = letters + digits + symbols // 94 ) -// Intn returns a int number which is between 0 and max: [0, max). +// Intn returns an int number which is between 0 and max: [0, max). // // Note that: // 1. The `max` can only be greater than 0, or else it returns `max` directly; @@ -95,7 +94,7 @@ func S(n int, symbols ...bool) string { b[i] = characters[numberBytes[i]%62] } } - return *(*string)(unsafe.Pointer(&b)) + return string(b) } // D returns a random time.Duration between min and max: [min, max]. @@ -147,7 +146,7 @@ func Digits(n int) string { for i := range b { b[i] = digits[numberBytes[i]%10] } - return *(*string)(unsafe.Pointer(&b)) + return string(b) } // Letters returns a random string which contains only letters, and its length is `n`. @@ -162,7 +161,7 @@ func Letters(n int) string { for i := range b { b[i] = letters[numberBytes[i]%52] } - return *(*string)(unsafe.Pointer(&b)) + return string(b) } // Symbols returns a random string which contains only symbols, and its length is `n`. @@ -177,7 +176,7 @@ func Symbols(n int) string { for i := range b { b[i] = symbols[numberBytes[i]%32] } - return *(*string)(unsafe.Pointer(&b)) + return string(b) } // Perm returns, as a slice of n int numbers, a pseudo-random permutation of the integers [0,n).