mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
remove usage of package unsafe for package gtype/grand
This commit is contained in:
@ -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...)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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),
|
||||
) {
|
||||
|
||||
@ -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),
|
||||
) {
|
||||
|
||||
@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user