diff --git a/g/container/garray/garray_func.go b/g/container/garray/garray_func.go index ed6ba8a11..a6375eab0 100644 --- a/g/container/garray/garray_func.go +++ b/g/container/garray/garray_func.go @@ -5,15 +5,3 @@ // You can obtain one at https://github.com/gogf/gf. package garray - -type apiSliceInterface interface { - Slice() []interface{} -} - -type apiSliceInt interface { - Slice() []int -} - -type apiSliceString interface { - Slice() []string -} diff --git a/g/container/garray/garray_normal_int.go b/g/container/garray/garray_normal_int.go index ae98e5fc4..31e62fc27 100644 --- a/g/container/garray/garray_normal_int.go +++ b/g/container/garray/garray_normal_int.go @@ -23,40 +23,40 @@ type IntArray struct { } // NewIntArray creates and returns an empty array. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewIntArray(unsafe ...bool) *IntArray { - return NewIntArraySize(0, 0, unsafe...) +func NewIntArray(safe ...bool) *IntArray { + return NewIntArraySize(0, 0, safe...) } // NewIntArraySize create and returns an array with given size and cap. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewIntArraySize(size int, cap int, unsafe ...bool) *IntArray { +func NewIntArraySize(size int, cap int, safe ...bool) *IntArray { return &IntArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: make([]int, size, cap), } } // NewIntArrayFrom creates and returns an array with given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewIntArrayFrom(array []int, unsafe ...bool) *IntArray { +func NewIntArrayFrom(array []int, safe ...bool) *IntArray { return &IntArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: array, } } // NewIntArrayFromCopy creates and returns an array from a copy of given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewIntArrayFromCopy(array []int, unsafe ...bool) *IntArray { +func NewIntArrayFromCopy(array []int, safe ...bool) *IntArray { newArray := make([]int, len(array)) copy(newArray, array) return &IntArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: newArray, } } diff --git a/g/container/garray/garray_normal_interface.go b/g/container/garray/garray_normal_interface.go index 315b439db..7b166b073 100644 --- a/g/container/garray/garray_normal_interface.go +++ b/g/container/garray/garray_normal_interface.go @@ -23,55 +23,55 @@ type Array struct { } // New creates and returns an empty array. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func New(unsafe ...bool) *Array { - return NewArraySize(0, 0, unsafe...) +func New(safe ...bool) *Array { + return NewArraySize(0, 0, safe...) } // See New. -func NewArray(unsafe ...bool) *Array { - return NewArraySize(0, 0, unsafe...) +func NewArray(safe ...bool) *Array { + return NewArraySize(0, 0, safe...) } // NewArraySize create and returns an array with given size and cap. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewArraySize(size int, cap int, unsafe ...bool) *Array { +func NewArraySize(size int, cap int, safe ...bool) *Array { return &Array{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: make([]interface{}, size, cap), } } // See NewArrayFrom. -func NewFrom(array []interface{}, unsafe ...bool) *Array { - return NewArrayFrom(array, unsafe...) +func NewFrom(array []interface{}, safe ...bool) *Array { + return NewArrayFrom(array, safe...) } // See NewArrayFromCopy. -func NewFromCopy(array []interface{}, unsafe ...bool) *Array { - return NewArrayFromCopy(array, unsafe...) +func NewFromCopy(array []interface{}, safe ...bool) *Array { + return NewArrayFromCopy(array, safe...) } // NewArrayFrom creates and returns an array with given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewArrayFrom(array []interface{}, unsafe ...bool) *Array { +func NewArrayFrom(array []interface{}, safe ...bool) *Array { return &Array{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: array, } } // NewArrayFromCopy creates and returns an array from a copy of given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewArrayFromCopy(array []interface{}, unsafe ...bool) *Array { +func NewArrayFromCopy(array []interface{}, safe ...bool) *Array { newArray := make([]interface{}, len(array)) copy(newArray, array) return &Array{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: newArray, } } diff --git a/g/container/garray/garray_normal_string.go b/g/container/garray/garray_normal_string.go index 0d88a1185..b489afb85 100644 --- a/g/container/garray/garray_normal_string.go +++ b/g/container/garray/garray_normal_string.go @@ -24,40 +24,40 @@ type StringArray struct { } // NewStringArray creates and returns an empty array. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewStringArray(unsafe ...bool) *StringArray { - return NewStringArraySize(0, 0, unsafe...) +func NewStringArray(safe ...bool) *StringArray { + return NewStringArraySize(0, 0, safe...) } // NewStringArraySize create and returns an array with given size and cap. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewStringArraySize(size int, cap int, unsafe ...bool) *StringArray { +func NewStringArraySize(size int, cap int, safe ...bool) *StringArray { return &StringArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: make([]string, size, cap), } } // NewStringArrayFrom creates and returns an array with given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewStringArrayFrom(array []string, unsafe ...bool) *StringArray { +func NewStringArrayFrom(array []string, safe ...bool) *StringArray { return &StringArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: array, } } // NewStringArrayFromCopy creates and returns an array from a copy of given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewStringArrayFromCopy(array []string, unsafe ...bool) *StringArray { +func NewStringArrayFromCopy(array []string, safe ...bool) *StringArray { newArray := make([]string, len(array)) copy(newArray, array) return &StringArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: newArray, } } diff --git a/g/container/garray/garray_sorted_int.go b/g/container/garray/garray_sorted_int.go index 0fb12ec8a..e9609720e 100644 --- a/g/container/garray/garray_sorted_int.go +++ b/g/container/garray/garray_sorted_int.go @@ -27,18 +27,18 @@ type SortedIntArray struct { } // NewSortedIntArray creates and returns an empty sorted array. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedIntArray(unsafe ...bool) *SortedIntArray { - return NewSortedIntArraySize(0, unsafe...) +func NewSortedIntArray(safe ...bool) *SortedIntArray { + return NewSortedIntArraySize(0, safe...) } // NewSortedIntArraySize create and returns an sorted array with given size and cap. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedIntArraySize(cap int, unsafe ...bool) *SortedIntArray { +func NewSortedIntArraySize(cap int, safe ...bool) *SortedIntArray { return &SortedIntArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: make([]int, 0, cap), unique: gtype.NewBool(), comparator: func(v1, v2 int) int { @@ -54,22 +54,22 @@ func NewSortedIntArraySize(cap int, unsafe ...bool) *SortedIntArray { } // NewIntArrayFrom creates and returns an sorted array with given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedIntArrayFrom(array []int, unsafe ...bool) *SortedIntArray { - a := NewSortedIntArraySize(0, unsafe...) +func NewSortedIntArrayFrom(array []int, safe ...bool) *SortedIntArray { + a := NewSortedIntArraySize(0, safe...) a.array = array sort.Ints(a.array) return a } // NewSortedIntArrayFromCopy creates and returns an sorted array from a copy of given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedIntArrayFromCopy(array []int, unsafe ...bool) *SortedIntArray { +func NewSortedIntArrayFromCopy(array []int, safe ...bool) *SortedIntArray { newArray := make([]int, len(array)) copy(newArray, array) - return NewSortedIntArrayFrom(newArray, unsafe...) + return NewSortedIntArrayFrom(newArray, safe...) } // SetArray sets the underlying slice array with the given . diff --git a/g/container/garray/garray_sorted_interface.go b/g/container/garray/garray_sorted_interface.go index d7b78b9d9..8962aeca7 100644 --- a/g/container/garray/garray_sorted_interface.go +++ b/g/container/garray/garray_sorted_interface.go @@ -27,21 +27,21 @@ type SortedArray struct { } // NewSortedArray creates and returns an empty sorted array. -// The parameter used to specify whether using array in un-concurrent-safety, which is false in default. +// The parameter used to specify whether using array in concurrent-safety, which is false in default. // The parameter used to compare values to sort in array, // if it returns value < 0, means v1 < v2; // if it returns value = 0, means v1 = v2; // if it returns value > 0, means v1 > v2; -func NewSortedArray(comparator func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray { - return NewSortedArraySize(0, comparator, unsafe...) +func NewSortedArray(comparator func(v1, v2 interface{}) int, safe ...bool) *SortedArray { + return NewSortedArraySize(0, comparator, safe...) } // NewSortedArraySize create and returns an sorted array with given size and cap. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedArraySize(cap int, comparator func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray { +func NewSortedArraySize(cap int, comparator func(v1, v2 interface{}) int, safe ...bool) *SortedArray { return &SortedArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), unique: gtype.NewBool(), array: make([]interface{}, 0, cap), comparator: comparator, @@ -49,10 +49,10 @@ func NewSortedArraySize(cap int, comparator func(v1, v2 interface{}) int, unsafe } // NewSortedArrayFrom creates and returns an sorted array with given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedArrayFrom(array []interface{}, comparator func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray { - a := NewSortedArraySize(0, comparator, unsafe...) +func NewSortedArrayFrom(array []interface{}, comparator func(v1, v2 interface{}) int, safe ...bool) *SortedArray { + a := NewSortedArraySize(0, comparator, safe...) a.array = array sort.Slice(a.array, func(i, j int) bool { return a.comparator(a.array[i], a.array[j]) < 0 @@ -61,12 +61,12 @@ func NewSortedArrayFrom(array []interface{}, comparator func(v1, v2 interface{}) } // NewSortedArrayFromCopy creates and returns an sorted array from a copy of given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedArrayFromCopy(array []interface{}, comparator func(v1, v2 interface{}) int, unsafe ...bool) *SortedArray { +func NewSortedArrayFromCopy(array []interface{}, comparator func(v1, v2 interface{}) int, safe ...bool) *SortedArray { newArray := make([]interface{}, len(array)) copy(newArray, array) - return NewSortedArrayFrom(newArray, comparator, unsafe...) + return NewSortedArrayFrom(newArray, comparator, safe...) } // SetArray sets the underlying slice array with the given . diff --git a/g/container/garray/garray_sorted_string.go b/g/container/garray/garray_sorted_string.go index be3cfa55f..601307e35 100644 --- a/g/container/garray/garray_sorted_string.go +++ b/g/container/garray/garray_sorted_string.go @@ -28,18 +28,18 @@ type SortedStringArray struct { } // NewSortedStringArray creates and returns an empty sorted array. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedStringArray(unsafe ...bool) *SortedStringArray { - return NewSortedStringArraySize(0, unsafe...) +func NewSortedStringArray(safe ...bool) *SortedStringArray { + return NewSortedStringArraySize(0, safe...) } // NewSortedStringArraySize create and returns an sorted array with given size and cap. -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedStringArraySize(cap int, unsafe ...bool) *SortedStringArray { +func NewSortedStringArraySize(cap int, safe ...bool) *SortedStringArray { return &SortedStringArray{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), array: make([]string, 0, cap), unique: gtype.NewBool(), comparator: func(v1, v2 string) int { @@ -49,22 +49,22 @@ func NewSortedStringArraySize(cap int, unsafe ...bool) *SortedStringArray { } // NewSortedStringArrayFrom creates and returns an sorted array with given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedStringArrayFrom(array []string, unsafe ...bool) *SortedStringArray { - a := NewSortedStringArraySize(0, unsafe...) +func NewSortedStringArrayFrom(array []string, safe ...bool) *SortedStringArray { + a := NewSortedStringArraySize(0, safe...) a.array = array sort.Strings(a.array) return a } // NewSortedStringArrayFromCopy creates and returns an sorted array from a copy of given slice . -// The parameter used to specify whether using array in un-concurrent-safety, +// The parameter used to specify whether using array in concurrent-safety, // which is false in default. -func NewSortedStringArrayFromCopy(array []string, unsafe ...bool) *SortedStringArray { +func NewSortedStringArrayFromCopy(array []string, safe ...bool) *SortedStringArray { newArray := make([]string, len(array)) copy(newArray, array) - return NewSortedStringArrayFrom(newArray, unsafe...) + return NewSortedStringArrayFrom(newArray, safe...) } // SetArray sets the underlying slice array with the given . diff --git a/g/container/garray/garray_z_example_test.go b/g/container/garray/garray_z_example_test.go index d32ef72c5..3711e8cd5 100644 --- a/g/container/garray/garray_z_example_test.go +++ b/g/container/garray/garray_z_example_test.go @@ -13,7 +13,7 @@ import ( func Example_basic() { // 创建普通的数组,默认并发安全(带锁) - a := garray.New() + a := garray.New(true) // 添加数据项 for i := 0; i < 10; i++ { diff --git a/g/container/garray/garray_z_unit_int_test.go b/g/container/garray/garray_z_unit_int_test.go index 1f43da646..d13aba193 100644 --- a/g/container/garray/garray_z_unit_int_test.go +++ b/g/container/garray/garray_z_unit_int_test.go @@ -659,7 +659,7 @@ func TestIntArray_Remove(t *testing.T) { func TestIntArray_LockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []int{1, 2, 3, 4} - a1 := garray.NewIntArrayFrom(s1) + a1 := garray.NewIntArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 3) @@ -704,7 +704,7 @@ func TestIntArray_SortFunc(t *testing.T) { func TestIntArray_RLockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []int{1, 2, 3, 4} - a1 := garray.NewIntArrayFrom(s1) + a1 := garray.NewIntArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 1) @@ -736,7 +736,7 @@ func TestIntArray_RLockFunc(t *testing.T) { func TestSortedIntArray_LockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []int{1, 2, 3, 4} - a1 := garray.NewSortedIntArrayFrom(s1) + a1 := garray.NewSortedIntArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 3) //go1 @@ -767,7 +767,7 @@ func TestSortedIntArray_LockFunc(t *testing.T) { func TestSortedIntArray_RLockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []int{1, 2, 3, 4} - a1 := garray.NewSortedIntArrayFrom(s1) + a1 := garray.NewSortedIntArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 1) diff --git a/g/container/garray/garray_z_unit_interface_test.go b/g/container/garray/garray_z_unit_interface_test.go index d4671f356..a1e16e20b 100644 --- a/g/container/garray/garray_z_unit_interface_test.go +++ b/g/container/garray/garray_z_unit_interface_test.go @@ -746,7 +746,7 @@ func TestSortedArray_LockFunc(t *testing.T) { return strings.Compare(gconv.String(v1), gconv.String(v2)) } s1 := []interface{}{"a", "b", "c", "d"} - a1 := garray.NewSortedArrayFrom(s1, func1) + a1 := garray.NewSortedArrayFrom(s1, func1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 3) @@ -781,7 +781,7 @@ func TestSortedArray_RLockFunc(t *testing.T) { return strings.Compare(gconv.String(v1), gconv.String(v2)) } s1 := []interface{}{"a", "b", "c", "d"} - a1 := garray.NewSortedArrayFrom(s1, func1) + a1 := garray.NewSortedArrayFrom(s1, func1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 3) @@ -844,7 +844,7 @@ func TestSortedArray_Merge(t *testing.T) { func TestArray_LockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []interface{}{"a", "b", "c", "d"} - a1 := garray.NewArrayFrom(s1) + a1 := garray.NewArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 3) @@ -876,7 +876,7 @@ func TestArray_LockFunc(t *testing.T) { func TestArray_RLockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []interface{}{"a", "b", "c", "d"} - a1 := garray.NewArrayFrom(s1) + a1 := garray.NewArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 1) diff --git a/g/container/garray/garray_z_unit_string_test.go b/g/container/garray/garray_z_unit_string_test.go index 4e8e8fd6e..99966f8ac 100644 --- a/g/container/garray/garray_z_unit_string_test.go +++ b/g/container/garray/garray_z_unit_string_test.go @@ -700,7 +700,7 @@ func TestStringArray_RLockFunc(t *testing.T) { func TestSortedStringArray_LockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []string{"a", "b", "c", "d"} - a1 := garray.NewSortedStringArrayFrom(s1) + a1 := garray.NewSortedStringArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 3) @@ -732,7 +732,7 @@ func TestSortedStringArray_LockFunc(t *testing.T) { func TestSortedStringArray_RLockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []string{"a", "b", "c", "d"} - a1 := garray.NewSortedStringArrayFrom(s1) + a1 := garray.NewSortedStringArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 1) @@ -805,7 +805,7 @@ func TestStringArray_SortFunc(t *testing.T) { func TestStringArray_LockFunc(t *testing.T) { gtest.Case(t, func() { s1 := []string{"a", "b", "c", "d"} - a1 := garray.NewStringArrayFrom(s1) + a1 := garray.NewStringArrayFrom(s1, true) ch1 := make(chan int64, 3) ch2 := make(chan int64, 3) diff --git a/g/container/glist/glist.go b/g/container/glist/glist.go index 9209408c5..3c28a4773 100644 --- a/g/container/glist/glist.go +++ b/g/container/glist/glist.go @@ -23,9 +23,9 @@ type ( ) // New creates and returns a new empty doubly linked list. -func New(unsafe ...bool) *List { +func New(safe ...bool) *List { return &List{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), list: list.New(), } } diff --git a/g/container/gmap/gmap.go b/g/container/gmap/gmap.go index bfaca7600..50fd76830 100644 --- a/g/container/gmap/gmap.go +++ b/g/container/gmap/gmap.go @@ -12,10 +12,10 @@ type Map = AnyAnyMap type HashMap = AnyAnyMap // New returns an empty hash map. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func New(unsafe ...bool) *Map { - return NewAnyAnyMap(unsafe...) +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func New(safe ...bool) *Map { + return NewAnyAnyMap(safe...) } // NewFrom returns a hash map from given map . @@ -23,15 +23,15 @@ func New(unsafe ...bool) *Map { // there might be some concurrent-safe issues when changing the map outside. // The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. -func NewFrom(data map[interface{}]interface{}, unsafe ...bool) *Map { - return NewAnyAnyMapFrom(data, unsafe...) +func NewFrom(data map[interface{}]interface{}, safe ...bool) *Map { + return NewAnyAnyMapFrom(data, safe...) } // NewHashMap returns an empty hash map. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewHashMap(unsafe ...bool) *Map { - return NewAnyAnyMap(unsafe...) +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewHashMap(safe ...bool) *Map { + return NewAnyAnyMap(safe...) } // NewHashMapFrom returns a hash map from given map . @@ -39,6 +39,6 @@ func NewHashMap(unsafe ...bool) *Map { // there might be some concurrent-safe issues when changing the map outside. // The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. -func NewHashMapFrom(data map[interface{}]interface{}, unsafe ...bool) *Map { - return NewAnyAnyMapFrom(data, unsafe...) +func NewHashMapFrom(data map[interface{}]interface{}, safe ...bool) *Map { + return NewAnyAnyMapFrom(data, safe...) } diff --git a/g/container/gmap/gmap_hash_any_any_map.go b/g/container/gmap/gmap_hash_any_any_map.go index db751099c..2643fca78 100644 --- a/g/container/gmap/gmap_hash_any_any_map.go +++ b/g/container/gmap/gmap_hash_any_any_map.go @@ -21,11 +21,11 @@ type AnyAnyMap struct { } // NewAnyAnyMap returns an empty hash map. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewAnyAnyMap(unsafe ...bool) *AnyAnyMap { +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewAnyAnyMap(safe ...bool) *AnyAnyMap { return &AnyAnyMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: make(map[interface{}]interface{}), } } @@ -33,9 +33,9 @@ func NewAnyAnyMap(unsafe ...bool) *AnyAnyMap { // NewAnyAnyMapFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -func NewAnyAnyMapFrom(data map[interface{}]interface{}, unsafe ...bool) *AnyAnyMap { +func NewAnyAnyMapFrom(data map[interface{}]interface{}, safe ...bool) *AnyAnyMap { return &AnyAnyMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: data, } } @@ -53,8 +53,8 @@ func (m *AnyAnyMap) Iterator(f func(k interface{}, v interface{}) bool) { } // Clone returns a new hash map with copy of current map data. -func (m *AnyAnyMap) Clone(unsafe ...bool) *AnyAnyMap { - return NewFrom(m.Map(), unsafe...) +func (m *AnyAnyMap) Clone(safe ...bool) *AnyAnyMap { + return NewFrom(m.Map(), safe...) } // Map returns a copy of the data of the hash map. @@ -161,25 +161,25 @@ func (m *AnyAnyMap) GetOrSetFuncLock(key interface{}, f func() interface{}) inte // GetVar returns a gvar.Var with the value by given . // The returned gvar.Var is un-concurrent safe. func (m *AnyAnyMap) GetVar(key interface{}) *gvar.Var { - return gvar.New(m.Get(key), true) + return gvar.New(m.Get(key)) } // GetVarOrSet returns a gvar.Var with result from GetVarOrSet. // The returned gvar.Var is un-concurrent safe. func (m *AnyAnyMap) GetVarOrSet(key interface{}, value interface{}) *gvar.Var { - return gvar.New(m.GetOrSet(key, value), true) + return gvar.New(m.GetOrSet(key, value)) } // GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. // The returned gvar.Var is un-concurrent safe. func (m *AnyAnyMap) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(m.GetOrSetFunc(key, f), true) + return gvar.New(m.GetOrSetFunc(key, f)) } // GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. // The returned gvar.Var is un-concurrent safe. func (m *AnyAnyMap) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(m.GetOrSetFuncLock(key, f), true) + return gvar.New(m.GetOrSetFuncLock(key, f)) } // SetIfNotExist sets to the map if the does not exist, then return true. diff --git a/g/container/gmap/gmap_hash_int_any_map.go b/g/container/gmap/gmap_hash_int_any_map.go index 1645fcc10..f25de6cda 100644 --- a/g/container/gmap/gmap_hash_int_any_map.go +++ b/g/container/gmap/gmap_hash_int_any_map.go @@ -21,11 +21,11 @@ type IntAnyMap struct { } // NewIntAnyMap returns an empty IntAnyMap object. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewIntAnyMap(unsafe ...bool) *IntAnyMap { +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewIntAnyMap(safe ...bool) *IntAnyMap { return &IntAnyMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: make(map[int]interface{}), } } @@ -33,9 +33,9 @@ func NewIntAnyMap(unsafe ...bool) *IntAnyMap { // NewIntAnyMapFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -func NewIntAnyMapFrom(data map[int]interface{}, unsafe ...bool) *IntAnyMap { +func NewIntAnyMapFrom(data map[int]interface{}, safe ...bool) *IntAnyMap { return &IntAnyMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: data, } } @@ -161,25 +161,25 @@ func (m *IntAnyMap) GetOrSetFuncLock(key int, f func() interface{}) interface{} // GetVar returns a gvar.Var with the value by given . // The returned gvar.Var is un-concurrent safe. func (m *IntAnyMap) GetVar(key int) *gvar.Var { - return gvar.New(m.Get(key), true) + return gvar.New(m.Get(key)) } // GetVarOrSet returns a gvar.Var with result from GetVarOrSet. // The returned gvar.Var is un-concurrent safe. func (m *IntAnyMap) GetVarOrSet(key int, value interface{}) *gvar.Var { - return gvar.New(m.GetOrSet(key, value), true) + return gvar.New(m.GetOrSet(key, value)) } // GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. // The returned gvar.Var is un-concurrent safe. func (m *IntAnyMap) GetVarOrSetFunc(key int, f func() interface{}) *gvar.Var { - return gvar.New(m.GetOrSetFunc(key, f), true) + return gvar.New(m.GetOrSetFunc(key, f)) } // GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. // The returned gvar.Var is un-concurrent safe. func (m *IntAnyMap) GetVarOrSetFuncLock(key int, f func() interface{}) *gvar.Var { - return gvar.New(m.GetOrSetFuncLock(key, f), true) + return gvar.New(m.GetOrSetFuncLock(key, f)) } // SetIfNotExist sets to the map if the does not exist, then return true. diff --git a/g/container/gmap/gmap_hash_int_int_map.go b/g/container/gmap/gmap_hash_int_int_map.go index 637989003..02c81d42d 100644 --- a/g/container/gmap/gmap_hash_int_int_map.go +++ b/g/container/gmap/gmap_hash_int_int_map.go @@ -18,11 +18,11 @@ type IntIntMap struct { } // NewIntIntMap returns an empty IntIntMap object. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewIntIntMap(unsafe ...bool) *IntIntMap { +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewIntIntMap(safe ...bool) *IntIntMap { return &IntIntMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: make(map[int]int), } } @@ -30,9 +30,9 @@ func NewIntIntMap(unsafe ...bool) *IntIntMap { // NewIntIntMapFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -func NewIntIntMapFrom(data map[int]int, unsafe ...bool) *IntIntMap { +func NewIntIntMapFrom(data map[int]int, safe ...bool) *IntIntMap { return &IntIntMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: data, } } diff --git a/g/container/gmap/gmap_hash_int_str_map.go b/g/container/gmap/gmap_hash_int_str_map.go index 225c370df..41c0c6d7f 100644 --- a/g/container/gmap/gmap_hash_int_str_map.go +++ b/g/container/gmap/gmap_hash_int_str_map.go @@ -19,11 +19,11 @@ type IntStrMap struct { } // NewIntStrMap returns an empty IntStrMap object. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewIntStrMap(unsafe ...bool) *IntStrMap { +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewIntStrMap(safe ...bool) *IntStrMap { return &IntStrMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: make(map[int]string), } } @@ -31,9 +31,9 @@ func NewIntStrMap(unsafe ...bool) *IntStrMap { // NewIntStrMapFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -func NewIntStrMapFrom(data map[int]string, unsafe ...bool) *IntStrMap { +func NewIntStrMapFrom(data map[int]string, safe ...bool) *IntStrMap { return &IntStrMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: data, } } diff --git a/g/container/gmap/gmap_hash_str_any_map.go b/g/container/gmap/gmap_hash_str_any_map.go index 5e2b4d117..ab0327969 100644 --- a/g/container/gmap/gmap_hash_str_any_map.go +++ b/g/container/gmap/gmap_hash_str_any_map.go @@ -21,11 +21,11 @@ type StrAnyMap struct { } // NewStrAnyMap returns an empty StrAnyMap object. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewStrAnyMap(unsafe ...bool) *StrAnyMap { +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewStrAnyMap(safe ...bool) *StrAnyMap { return &StrAnyMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: make(map[string]interface{}), } } @@ -33,9 +33,9 @@ func NewStrAnyMap(unsafe ...bool) *StrAnyMap { // NewStrAnyMapFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -func NewStrAnyMapFrom(data map[string]interface{}, unsafe ...bool) *StrAnyMap { +func NewStrAnyMapFrom(data map[string]interface{}, safe ...bool) *StrAnyMap { return &StrAnyMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: data, } } @@ -163,25 +163,25 @@ func (m *StrAnyMap) GetOrSetFuncLock(key string, f func() interface{}) interface // GetVar returns a gvar.Var with the value by given . // The returned gvar.Var is un-concurrent safe. func (m *StrAnyMap) GetVar(key string) *gvar.Var { - return gvar.New(m.Get(key), true) + return gvar.New(m.Get(key)) } // GetVarOrSet returns a gvar.Var with result from GetVarOrSet. // The returned gvar.Var is un-concurrent safe. func (m *StrAnyMap) GetVarOrSet(key string, value interface{}) *gvar.Var { - return gvar.New(m.GetOrSet(key, value), true) + return gvar.New(m.GetOrSet(key, value)) } // GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. // The returned gvar.Var is un-concurrent safe. func (m *StrAnyMap) GetVarOrSetFunc(key string, f func() interface{}) *gvar.Var { - return gvar.New(m.GetOrSetFunc(key, f), true) + return gvar.New(m.GetOrSetFunc(key, f)) } // GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. // The returned gvar.Var is un-concurrent safe. func (m *StrAnyMap) GetVarOrSetFuncLock(key string, f func() interface{}) *gvar.Var { - return gvar.New(m.GetOrSetFuncLock(key, f), true) + return gvar.New(m.GetOrSetFuncLock(key, f)) } // SetIfNotExist sets to the map if the does not exist, then return true. diff --git a/g/container/gmap/gmap_hash_str_int_map.go b/g/container/gmap/gmap_hash_str_int_map.go index df7e13b12..c006398e9 100644 --- a/g/container/gmap/gmap_hash_str_int_map.go +++ b/g/container/gmap/gmap_hash_str_int_map.go @@ -20,11 +20,11 @@ type StrIntMap struct { } // NewStrIntMap returns an empty StrIntMap object. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewStrIntMap(unsafe ...bool) *StrIntMap { +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewStrIntMap(safe ...bool) *StrIntMap { return &StrIntMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: make(map[string]int), } } @@ -32,9 +32,9 @@ func NewStrIntMap(unsafe ...bool) *StrIntMap { // NewStrIntMapFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -func NewStrIntMapFrom(data map[string]int, unsafe ...bool) *StrIntMap { +func NewStrIntMapFrom(data map[string]int, safe ...bool) *StrIntMap { return &StrIntMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: data, } } diff --git a/g/container/gmap/gmap_hash_str_str_map.go b/g/container/gmap/gmap_hash_str_str_map.go index ef03174b3..2c93394ff 100644 --- a/g/container/gmap/gmap_hash_str_str_map.go +++ b/g/container/gmap/gmap_hash_str_str_map.go @@ -19,21 +19,21 @@ type StrStrMap struct { } // NewStrStrMap returns an empty StrStrMap object. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewStrStrMap(unsafe ...bool) *StrStrMap { +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewStrStrMap(safe ...bool) *StrStrMap { return &StrStrMap{ data: make(map[string]string), - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), } } // NewStrStrMapFrom returns a hash map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -func NewStrStrMapFrom(data map[string]string, unsafe ...bool) *StrStrMap { +func NewStrStrMapFrom(data map[string]string, safe ...bool) *StrStrMap { return &StrStrMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: data, } } diff --git a/g/container/gmap/gmap_link_map.go b/g/container/gmap/gmap_link_map.go index 36e61f2c6..ebc3a3884 100644 --- a/g/container/gmap/gmap_link_map.go +++ b/g/container/gmap/gmap_link_map.go @@ -29,21 +29,21 @@ type gListMapNode struct { // NewListMap returns an empty link map. // ListMap is backed by a hash table to store values and doubly-linked list to store ordering. -// The parameter used to specify whether using map in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func NewListMap(unsafe ...bool) *ListMap { +// The parameter used to specify whether using map in concurrent-safety, +// which is false in default. +func NewListMap(safe ...bool) *ListMap { return &ListMap{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), data: make(map[interface{}]*glist.Element), - list: glist.New(true), + list: glist.New(), } } // NewListMapFrom returns a link map from given map . // Note that, the param map will be set as the underlying data map(no deep copy), // there might be some concurrent-safe issues when changing the map outside. -func NewListMapFrom(data map[interface{}]interface{}, unsafe ...bool) *ListMap { - m := NewListMap(unsafe...) +func NewListMapFrom(data map[interface{}]interface{}, safe ...bool) *ListMap { + m := NewListMap(safe...) m.Sets(data) return m } @@ -78,15 +78,15 @@ func (m *ListMap) IteratorDesc(f func(key interface{}, value interface{}) bool) } // Clone returns a new link map with copy of current map data. -func (m *ListMap) Clone(unsafe ...bool) *ListMap { - return NewListMapFrom(m.Map(), unsafe...) +func (m *ListMap) Clone(safe ...bool) *ListMap { + return NewListMapFrom(m.Map(), safe...) } // Clear deletes all data of the map, it will remake a new underlying data map. func (m *ListMap) Clear() { m.mu.Lock() m.data = make(map[interface{}]*glist.Element) - m.list = glist.New(true) + m.list = glist.New() m.mu.Unlock() } @@ -210,25 +210,25 @@ func (m *ListMap) GetOrSetFuncLock(key interface{}, f func() interface{}) interf // GetVar returns a gvar.Var with the value by given . // The returned gvar.Var is un-concurrent safe. func (m *ListMap) GetVar(key interface{}) *gvar.Var { - return gvar.New(m.Get(key), true) + return gvar.New(m.Get(key)) } // GetVarOrSet returns a gvar.Var with result from GetVarOrSet. // The returned gvar.Var is un-concurrent safe. func (m *ListMap) GetVarOrSet(key interface{}, value interface{}) *gvar.Var { - return gvar.New(m.GetOrSet(key, value), true) + return gvar.New(m.GetOrSet(key, value)) } // GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. // The returned gvar.Var is un-concurrent safe. func (m *ListMap) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(m.GetOrSetFunc(key, f), true) + return gvar.New(m.GetOrSetFunc(key, f)) } // GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. // The returned gvar.Var is un-concurrent safe. func (m *ListMap) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(m.GetOrSetFuncLock(key, f), true) + return gvar.New(m.GetOrSetFuncLock(key, f)) } // SetIfNotExist sets to the map if the does not exist, then return true. diff --git a/g/container/gmap/gmap_tree_map.go b/g/container/gmap/gmap_tree_map.go index 240ff4cd1..cf1a7b1e5 100644 --- a/g/container/gmap/gmap_tree_map.go +++ b/g/container/gmap/gmap_tree_map.go @@ -16,8 +16,8 @@ type TreeMap = gtree.RedBlackTree // NewTreeMap instantiates a tree map with the custom comparator. // The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. -func NewTreeMap(comparator func(v1, v2 interface{}) int, unsafe ...bool) *TreeMap { - return gtree.NewRedBlackTree(comparator, unsafe...) +func NewTreeMap(comparator func(v1, v2 interface{}) int, safe ...bool) *TreeMap { + return gtree.NewRedBlackTree(comparator, safe...) } // NewTreeMapFrom instantiates a tree map with the custom comparator and map. @@ -25,6 +25,6 @@ func NewTreeMap(comparator func(v1, v2 interface{}) int, unsafe ...bool) *TreeMa // there might be some concurrent-safe issues when changing the map outside. // The parameter used to specify whether using tree in un-concurrent-safety, // which is false in default. -func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *TreeMap { - return gtree.NewRedBlackTreeFrom(comparator, data, unsafe...) +func NewTreeMapFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *TreeMap { + return gtree.NewRedBlackTreeFrom(comparator, data, safe...) } diff --git a/g/container/gpool/gpool.go b/g/container/gpool/gpool.go index 508105183..343c0622b 100644 --- a/g/container/gpool/gpool.go +++ b/g/container/gpool/gpool.go @@ -51,7 +51,7 @@ type ExpireFunc func(interface{}) // Note that the expiration time unit is ** milliseconds **. func New(expire int, newFunc NewFunc, expireFunc ...ExpireFunc) *Pool { r := &Pool{ - list: glist.New(), + list: glist.New(true), closed: gtype.NewBool(), Expire: int64(expire), NewFunc: newFunc, diff --git a/g/container/gqueue/gqueue.go b/g/container/gqueue/gqueue.go index 369f86bf6..8362c25cf 100644 --- a/g/container/gqueue/gqueue.go +++ b/g/container/gqueue/gqueue.go @@ -50,7 +50,7 @@ func New(limit ...int) *Queue { q.limit = limit[0] q.C = make(chan interface{}, limit[0]) } else { - q.list = glist.New() + q.list = glist.New(true) q.events = make(chan struct{}, math.MaxInt32) q.C = make(chan interface{}, gDEFAULT_QUEUE_SIZE) go q.startAsyncLoop() diff --git a/g/container/gring/gring.go b/g/container/gring/gring.go index 0979a7dca..eb22508a9 100644 --- a/g/container/gring/gring.go +++ b/g/container/gring/gring.go @@ -18,13 +18,12 @@ type Ring struct { ring *ring.Ring // Underlying ring. len *gtype.Int // Length(already used size). cap *gtype.Int // Capability(>=len). - dirty *gtype.Bool // Dirty, which means the len and cap should be recalculated. - // It's marked dirty when the size of ring changes. + dirty *gtype.Bool // Dirty, which means the len and cap should be recalculated. It's marked dirty when the size of ring changes. } -func New(cap int, unsafe ...bool) *Ring { +func New(cap int, safe ...bool) *Ring { return &Ring{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), ring: ring.New(cap), len: gtype.NewInt(), cap: gtype.NewInt(cap), diff --git a/g/container/gset/gset.go b/g/container/gset/gset.go index 1775fe240..52b74d68a 100644 --- a/g/container/gset/gset.go +++ b/g/container/gset/gset.go @@ -21,28 +21,28 @@ type Set struct { // New create and returns a new set, which contains un-repeated items. // The parameter used to specify whether using set in un-concurrent-safety, // which is false in default. -func New(unsafe ...bool) *Set { - return NewSet(unsafe...) +func New(safe ...bool) *Set { + return NewSet(safe...) } // See New. -func NewSet(unsafe ...bool) *Set { +func NewSet(safe ...bool) *Set { return &Set{ m: make(map[interface{}]struct{}), - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), } } // NewFrom returns a new set from . // Parameter can be either a variable of any type, or a slice. -func NewFrom(items interface{}, unsafe ...bool) *Set { +func NewFrom(items interface{}, safe ...bool) *Set { m := make(map[interface{}]struct{}) for _, v := range gconv.Interfaces(items) { m[v] = struct{}{} } return &Set{ m: m, - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), } } diff --git a/g/container/gset/gset_int_set.go b/g/container/gset/gset_int_set.go index 2381a68ae..f8e0541ee 100644 --- a/g/container/gset/gset_int_set.go +++ b/g/container/gset/gset_int_set.go @@ -21,22 +21,22 @@ type IntSet struct { // New create and returns a new set, which contains un-repeated items. // The parameter used to specify whether using set in un-concurrent-safety, // which is false in default. -func NewIntSet(unsafe ...bool) *IntSet { +func NewIntSet(safe ...bool) *IntSet { return &IntSet{ m: make(map[int]struct{}), - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), } } // NewIntSetFrom returns a new set from . -func NewIntSetFrom(items []int, unsafe ...bool) *IntSet { +func NewIntSetFrom(items []int, safe ...bool) *IntSet { m := make(map[int]struct{}) for _, v := range items { m[v] = struct{}{} } return &IntSet{ m: m, - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), } } diff --git a/g/container/gset/gset_string_set.go b/g/container/gset/gset_string_set.go index bf175950b..7a0c68251 100644 --- a/g/container/gset/gset_string_set.go +++ b/g/container/gset/gset_string_set.go @@ -21,22 +21,22 @@ type StringSet struct { // New create and returns a new set, which contains un-repeated items. // The parameter used to specify whether using set in un-concurrent-safety, // which is false in default. -func NewStringSet(unsafe ...bool) *StringSet { +func NewStringSet(safe ...bool) *StringSet { return &StringSet{ m: make(map[string]struct{}), - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), } } // NewStringSetFrom returns a new set from . -func NewStringSetFrom(items []string, unsafe ...bool) *StringSet { +func NewStringSetFrom(items []string, safe ...bool) *StringSet { m := make(map[string]struct{}) for _, v := range items { m[v] = struct{}{} } return &StringSet{ m: m, - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), } } diff --git a/g/container/gset/gset_z_unit_int_test.go b/g/container/gset/gset_z_unit_int_test.go index 4a640c205..d9b707c52 100644 --- a/g/container/gset/gset_z_unit_int_test.go +++ b/g/container/gset/gset_z_unit_int_test.go @@ -42,8 +42,8 @@ func TestIntSet_Iterator(t *testing.T) { s.Add(1).Add(2).Add(3) gtest.Assert(s.Size(), 3) - a1 := garray.New() - a2 := garray.New() + a1 := garray.New(true) + a2 := garray.New(true) s.Iterator(func(v int) bool { a1.Append(1) return false diff --git a/g/container/gset/gset_z_unit_string_test.go b/g/container/gset/gset_z_unit_string_test.go index c75c2f10b..57354d803 100644 --- a/g/container/gset/gset_z_unit_string_test.go +++ b/g/container/gset/gset_z_unit_string_test.go @@ -42,8 +42,8 @@ func TestStringSet_Iterator(t *testing.T) { s.Add("1").Add("2").Add("3") gtest.Assert(s.Size(), 3) - a1 := garray.New() - a2 := garray.New() + a1 := garray.New(true) + a2 := garray.New(true) s.Iterator(func(v string) bool { a1.Append("1") return false diff --git a/g/container/gset/gset_z_unit_test.go b/g/container/gset/gset_z_unit_test.go index 9a5f54a20..fba78f7ee 100644 --- a/g/container/gset/gset_z_unit_test.go +++ b/g/container/gset/gset_z_unit_test.go @@ -63,8 +63,8 @@ func TestSet_Iterator(t *testing.T) { s.Add(1).Add(2).Add(3) gtest.Assert(s.Size(), 3) - a1 := garray.New() - a2 := garray.New() + a1 := garray.New(true) + a2 := garray.New(true) s.Iterator(func(v interface{}) bool { a1.Append(1) return false diff --git a/g/container/gtree/gtree_avltree.go b/g/container/gtree/gtree_avltree.go index e8bd607ad..760bb6948 100644 --- a/g/container/gtree/gtree_avltree.go +++ b/g/container/gtree/gtree_avltree.go @@ -32,20 +32,20 @@ type AVLTreeNode struct { } // NewAVLTree instantiates an AVL tree with the custom key comparator. -// The parameter used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in concurrent-safety, // which is false in default. -func NewAVLTree(comparator func(v1, v2 interface{}) int, unsafe ...bool) *AVLTree { +func NewAVLTree(comparator func(v1, v2 interface{}) int, safe ...bool) *AVLTree { return &AVLTree{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), comparator: comparator, } } // NewAVLTreeFrom instantiates an AVL tree with the custom key comparator and data map. -// The parameter used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in concurrent-safety, // which is false in default. -func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *AVLTree { - tree := NewAVLTree(comparator, unsafe...) +func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *AVLTree { + tree := NewAVLTree(comparator, safe...) for k, v := range data { tree.put(k, v, nil, &tree.root) } @@ -53,7 +53,7 @@ func NewAVLTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{ } // Clone returns a new tree with a copy of current tree. -func (tree *AVLTree) Clone(unsafe ...bool) *AVLTree { +func (tree *AVLTree) Clone(safe ...bool) *AVLTree { newTree := NewAVLTree(tree.comparator, !tree.mu.IsSafe()) newTree.Sets(tree.Map()) return newTree @@ -167,25 +167,25 @@ func (tree *AVLTree) GetOrSetFuncLock(key interface{}, f func() interface{}) int // GetVar returns a gvar.Var with the value by given . // The returned gvar.Var is un-concurrent safe. func (tree *AVLTree) GetVar(key interface{}) *gvar.Var { - return gvar.New(tree.Get(key), true) + return gvar.New(tree.Get(key)) } // GetVarOrSet returns a gvar.Var with result from GetVarOrSet. // The returned gvar.Var is un-concurrent safe. func (tree *AVLTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var { - return gvar.New(tree.GetOrSet(key, value), true) + return gvar.New(tree.GetOrSet(key, value)) } // GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. // The returned gvar.Var is un-concurrent safe. func (tree *AVLTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(tree.GetOrSetFunc(key, f), true) + return gvar.New(tree.GetOrSetFunc(key, f)) } // GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. // The returned gvar.Var is un-concurrent safe. func (tree *AVLTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(tree.GetOrSetFuncLock(key, f), true) + return gvar.New(tree.GetOrSetFuncLock(key, f)) } // SetIfNotExist sets to the map if the does not exist, then return true. diff --git a/g/container/gtree/gtree_btree.go b/g/container/gtree/gtree_btree.go index 799ab0294..2e3c46788 100644 --- a/g/container/gtree/gtree_btree.go +++ b/g/container/gtree/gtree_btree.go @@ -39,25 +39,25 @@ type BTreeEntry struct { } // NewBTree instantiates a B-tree with (maximum number of children) and a custom key comparator. -// The parameter used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in concurrent-safety, // which is false in default. // Note that the must be greater or equal than 3, or else it panics. -func NewBTree(m int, comparator func(v1, v2 interface{}) int, unsafe ...bool) *BTree { +func NewBTree(m int, comparator func(v1, v2 interface{}) int, safe ...bool) *BTree { if m < 3 { panic("Invalid order, should be at least 3") } return &BTree{ comparator: comparator, - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), m: m, } } // NewBTreeFrom instantiates a B-tree with (maximum number of children), a custom key comparator and data map. -// The parameter used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in concurrent-safety, // which is false in default. -func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *BTree { - tree := NewBTree(m, comparator, unsafe...) +func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *BTree { + tree := NewBTree(m, comparator, safe...) for k, v := range data { tree.doSet(k, v) } @@ -65,7 +65,7 @@ func NewBTreeFrom(m int, comparator func(v1, v2 interface{}) int, data map[inter } // Clone returns a new tree with a copy of current tree. -func (tree *BTree) Clone(unsafe ...bool) *BTree { +func (tree *BTree) Clone(safe ...bool) *BTree { newTree := NewBTree(tree.m, tree.comparator, !tree.mu.IsSafe()) newTree.Sets(tree.Map()) return newTree @@ -168,25 +168,25 @@ func (tree *BTree) GetOrSetFuncLock(key interface{}, f func() interface{}) inter // GetVar returns a gvar.Var with the value by given . // The returned gvar.Var is un-concurrent safe. func (tree *BTree) GetVar(key interface{}) *gvar.Var { - return gvar.New(tree.Get(key), true) + return gvar.New(tree.Get(key)) } // GetVarOrSet returns a gvar.Var with result from GetVarOrSet. // The returned gvar.Var is un-concurrent safe. func (tree *BTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var { - return gvar.New(tree.GetOrSet(key, value), true) + return gvar.New(tree.GetOrSet(key, value)) } // GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. // The returned gvar.Var is un-concurrent safe. func (tree *BTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(tree.GetOrSetFunc(key, f), true) + return gvar.New(tree.GetOrSetFunc(key, f)) } // GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. // The returned gvar.Var is un-concurrent safe. func (tree *BTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(tree.GetOrSetFuncLock(key, f), true) + return gvar.New(tree.GetOrSetFuncLock(key, f)) } // SetIfNotExist sets to the map if the does not exist, then return true. diff --git a/g/container/gtree/gtree_redblacktree.go b/g/container/gtree/gtree_redblacktree.go index 4bfe76a08..00da32861 100644 --- a/g/container/gtree/gtree_redblacktree.go +++ b/g/container/gtree/gtree_redblacktree.go @@ -39,20 +39,20 @@ type RedBlackTreeNode struct { } // NewRedBlackTree instantiates a red-black tree with the custom key comparator. -// The parameter used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in concurrent-safety, // which is false in default. -func NewRedBlackTree(comparator func(v1, v2 interface{}) int, unsafe ...bool) *RedBlackTree { +func NewRedBlackTree(comparator func(v1, v2 interface{}) int, safe ...bool) *RedBlackTree { return &RedBlackTree{ - mu: rwmutex.New(unsafe...), + mu: rwmutex.New(safe...), comparator: comparator, } } // NewRedBlackTreeFrom instantiates a red-black tree with the custom key comparator and map. -// The parameter used to specify whether using tree in un-concurrent-safety, +// The parameter used to specify whether using tree in concurrent-safety, // which is false in default. -func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, unsafe ...bool) *RedBlackTree { - tree := NewRedBlackTree(comparator, unsafe...) +func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[interface{}]interface{}, safe ...bool) *RedBlackTree { + tree := NewRedBlackTree(comparator, safe...) for k, v := range data { tree.doSet(k, v) } @@ -60,7 +60,7 @@ func NewRedBlackTreeFrom(comparator func(v1, v2 interface{}) int, data map[inter } // Clone returns a new tree with a copy of current tree. -func (tree *RedBlackTree) Clone(unsafe ...bool) *RedBlackTree { +func (tree *RedBlackTree) Clone(safe ...bool) *RedBlackTree { newTree := NewRedBlackTree(tree.comparator, !tree.mu.IsSafe()) newTree.Sets(tree.Map()) return newTree @@ -190,25 +190,25 @@ func (tree *RedBlackTree) GetOrSetFuncLock(key interface{}, f func() interface{} // GetVar returns a gvar.Var with the value by given . // The returned gvar.Var is un-concurrent safe. func (tree *RedBlackTree) GetVar(key interface{}) *gvar.Var { - return gvar.New(tree.Get(key), true) + return gvar.New(tree.Get(key)) } // GetVarOrSet returns a gvar.Var with result from GetVarOrSet. // The returned gvar.Var is un-concurrent safe. func (tree *RedBlackTree) GetVarOrSet(key interface{}, value interface{}) *gvar.Var { - return gvar.New(tree.GetOrSet(key, value), true) + return gvar.New(tree.GetOrSet(key, value)) } // GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc. // The returned gvar.Var is un-concurrent safe. func (tree *RedBlackTree) GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(tree.GetOrSetFunc(key, f), true) + return gvar.New(tree.GetOrSetFunc(key, f)) } // GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock. // The returned gvar.Var is un-concurrent safe. func (tree *RedBlackTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var { - return gvar.New(tree.GetOrSetFuncLock(key, f), true) + return gvar.New(tree.GetOrSetFuncLock(key, f)) } // SetIfNotExist sets to the map if the does not exist, then return true. diff --git a/g/container/gvar/gvar.go b/g/container/gvar/gvar.go index acc554414..7cb88bdaa 100644 --- a/g/container/gvar/gvar.go +++ b/g/container/gvar/gvar.go @@ -23,11 +23,11 @@ type Var struct { } // New returns a new Var with given . -// The parameter used to specify whether using Var in un-concurrent-safety, -// which is false in default, means concurrent-safe. -func New(value interface{}, unsafe ...bool) *Var { +// The parameter used to specify whether using Var in concurrent-safety, +// which is false in default. +func New(value interface{}, safe ...bool) *Var { v := &Var{} - if len(unsafe) == 0 || !unsafe[0] { + if len(safe) > 0 && !safe[0] { v.safe = true v.value = gtype.NewInterface(value) } else { diff --git a/g/database/gdb/gdb.go b/g/database/gdb/gdb.go index c9235e012..13fdb098e 100644 --- a/g/database/gdb/gdb.go +++ b/g/database/gdb/gdb.go @@ -162,7 +162,7 @@ const ( var ( // Instance map. - instances = gmap.NewStrAnyMap() + instances = gmap.NewStrAnyMap(true) ) // New creates ORM DB object with global configurations. diff --git a/g/database/gdb/gdb_base.go b/g/database/gdb/gdb_base.go index 4e6186570..3ea22680c 100644 --- a/g/database/gdb/gdb_base.go +++ b/g/database/gdb/gdb_base.go @@ -611,13 +611,13 @@ func (bs *dbBase) rowsToResult(rows *sql.Rows) (Result, error) { // 多个记录循环时该变量指向的是同一个内存地址 for i, column := range values { if column == nil { - row[columns[i]] = gvar.New(nil, true) + row[columns[i]] = gvar.New(nil) } else { // 由于 sql.RawBytes 是slice类型, 这里必须使用值复制 v := make([]byte, len(column)) copy(v, column) //fmt.Println(columns[i], types[i], string(v), v, bs.db.convertValue(v, types[i])) - row[columns[i]] = gvar.New(bs.db.convertValue(v, types[i]), true) + row[columns[i]] = gvar.New(bs.db.convertValue(v, types[i])) } } records = append(records, row) diff --git a/g/database/gdb/gdb_config.go b/g/database/gdb/gdb_config.go index 859db2e37..d77eade19 100644 --- a/g/database/gdb/gdb_config.go +++ b/g/database/gdb/gdb_config.go @@ -145,7 +145,7 @@ func (bs *dbBase) SetDebug(debug bool) { } bs.debug.Set(debug) if debug && bs.sqls == nil { - bs.sqls = gring.New(gDEFAULT_DEBUG_SQL_LENGTH) + bs.sqls = gring.New(gDEFAULT_DEBUG_SQL_LENGTH, true) } } diff --git a/g/database/gredis/gredis.go b/g/database/gredis/gredis.go index bac5a85b6..0edd55e43 100644 --- a/g/database/gredis/gredis.go +++ b/g/database/gredis/gredis.go @@ -57,9 +57,9 @@ type PoolStats struct { var ( // Instance map - instances = gmap.NewStrAnyMap() + instances = gmap.NewStrAnyMap(true) // Pool map. - pools = gmap.NewStrAnyMap() + pools = gmap.NewStrAnyMap(true) ) // New creates a redis client object with given configuration. @@ -177,8 +177,8 @@ func (r *Redis) Stats() *PoolStats { } // Do sends a command to the server and returns the received reply. -// Do automatically get a connection from pool, and close it when reply received. -// It does not really "close" the connection, but drop it back to the connection pool. +// Do automatically get a connection from pool, and close it when the reply received. +// It does not really "close" the connection, but drops it back to the connection pool. func (r *Redis) Do(command string, args ...interface{}) (interface{}, error) { conn := &Conn{r.pool.Get()} defer conn.Close() @@ -188,7 +188,7 @@ func (r *Redis) Do(command string, args ...interface{}) (interface{}, error) { // DoVar returns value from Do as gvar.Var. func (r *Redis) DoVar(command string, args ...interface{}) (*gvar.Var, error) { v, err := r.Do(command, args...) - return gvar.New(v, true), err + return gvar.New(v), err } // Deprecated. diff --git a/g/database/gredis/gredis_config.go b/g/database/gredis/gredis_config.go index 92480db22..bb17c6477 100644 --- a/g/database/gredis/gredis_config.go +++ b/g/database/gredis/gredis_config.go @@ -15,7 +15,7 @@ const ( var ( // Configuration groups. - configs = gmap.NewStrAnyMap() + configs = gmap.NewStrAnyMap(true) ) // SetConfig sets the global configuration for specified group. diff --git a/g/database/gredis/gredis_conn.go b/g/database/gredis/gredis_conn.go index 304b3325e..121bf2749 100644 --- a/g/database/gredis/gredis_conn.go +++ b/g/database/gredis/gredis_conn.go @@ -11,11 +11,11 @@ import "github.com/gogf/gf/g/container/gvar" // DoVar returns value from Do as gvar.Var. func (c *Conn) DoVar(command string, args ...interface{}) (*gvar.Var, error) { v, err := c.Do(command, args...) - return gvar.New(v, true), err + return gvar.New(v), err } // ReceiveVar receives a single reply as gvar.Var from the Redis server. func (c *Conn) ReceiveVar() (*gvar.Var, error) { v, err := c.Receive() - return gvar.New(v, true), err + return gvar.New(v), err } diff --git a/g/encoding/gjson/gjson_api.go b/g/encoding/gjson/gjson_api.go index 04854860a..8bf8aad58 100644 --- a/g/encoding/gjson/gjson_api.go +++ b/g/encoding/gjson/gjson_api.go @@ -60,7 +60,7 @@ func (j *Json) Get(pattern string, def ...interface{}) interface{} { // GetVar returns a *gvar.Var with value by given . func (j *Json) GetVar(pattern string, def ...interface{}) *gvar.Var { - return gvar.New(j.Get(pattern, def...), true) + return gvar.New(j.Get(pattern, def...)) } // GetMap gets the value by specified , @@ -76,7 +76,7 @@ func (j *Json) GetMap(pattern string, def ...interface{}) map[string]interface{} // GetJson gets the value by specified , // and converts it to a un-concurrent-safe Json object. func (j *Json) GetJson(pattern string, def ...interface{}) *Json { - return New(j.Get(pattern, def...), true) + return New(j.Get(pattern, def...)) } // GetJsons gets the value by specified , @@ -86,7 +86,7 @@ func (j *Json) GetJsons(pattern string, def ...interface{}) []*Json { if len(array) > 0 { jsonSlice := make([]*Json, len(array)) for i := 0; i < len(array); i++ { - jsonSlice[i] = New(array[i], true) + jsonSlice[i] = New(array[i]) } return jsonSlice } @@ -100,7 +100,7 @@ func (j *Json) GetJsonMap(pattern string, def ...interface{}) map[string]*Json { if len(m) > 0 { jsonMap := make(map[string]*Json, len(m)) for k, v := range m { - jsonMap[k] = New(v, true) + jsonMap[k] = New(v) } return jsonMap } diff --git a/g/encoding/gjson/gjson_api_new_load.go b/g/encoding/gjson/gjson_api_new_load.go index 220790e69..56a1f29ff 100644 --- a/g/encoding/gjson/gjson_api_new_load.go +++ b/g/encoding/gjson/gjson_api_new_load.go @@ -30,7 +30,7 @@ import ( // or it will make no sense. // The param specifies whether using this Json object // in un-concurrent-safe context, which is false in default. -func New(data interface{}, unsafe ...bool) *Json { +func New(data interface{}, safe ...bool) *Json { j := (*Json)(nil) switch data.(type) { case string, []byte: @@ -79,18 +79,10 @@ func New(data interface{}, unsafe ...bool) *Json { } } } - j.mu = rwmutex.New(unsafe...) + j.mu = rwmutex.New(safe...) return j } -// NewUnsafe creates a un-concurrent-safe Json object. -func NewUnsafe(data ...interface{}) *Json { - if len(data) > 0 { - return New(data[0], true) - } - return New(nil, true) -} - // Valid checks whether is a valid JSON data type. func Valid(data interface{}) bool { return json.Valid(gconv.Bytes(data)) @@ -120,41 +112,41 @@ func DecodeTo(data interface{}, v interface{}) error { } // DecodeToJson codes (string/[]byte) to a Json object. -func DecodeToJson(data interface{}, unsafe ...bool) (*Json, error) { +func DecodeToJson(data interface{}, safe ...bool) (*Json, error) { if v, err := Decode(gconv.Bytes(data)); err != nil { return nil, err } else { - return New(v, unsafe...), nil + return New(v, safe...), nil } } // Load loads content from specified file , // and creates a Json object from its content. -func Load(path string, unsafe ...bool) (*Json, error) { - return doLoadContent(gfile.Ext(path), gfcache.GetBinContents(path), unsafe...) +func Load(path string, safe ...bool) (*Json, error) { + return doLoadContent(gfile.Ext(path), gfcache.GetBinContents(path), safe...) } -func LoadJson(data interface{}, unsafe ...bool) (*Json, error) { - return doLoadContent("json", gconv.Bytes(data), unsafe...) +func LoadJson(data interface{}, safe ...bool) (*Json, error) { + return doLoadContent("json", gconv.Bytes(data), safe...) } -func LoadXml(data interface{}, unsafe ...bool) (*Json, error) { - return doLoadContent("xml", gconv.Bytes(data), unsafe...) +func LoadXml(data interface{}, safe ...bool) (*Json, error) { + return doLoadContent("xml", gconv.Bytes(data), safe...) } -func LoadYaml(data interface{}, unsafe ...bool) (*Json, error) { - return doLoadContent("yaml", gconv.Bytes(data), unsafe...) +func LoadYaml(data interface{}, safe ...bool) (*Json, error) { + return doLoadContent("yaml", gconv.Bytes(data), safe...) } -func LoadToml(data interface{}, unsafe ...bool) (*Json, error) { - return doLoadContent("toml", gconv.Bytes(data), unsafe...) +func LoadToml(data interface{}, safe ...bool) (*Json, error) { + return doLoadContent("toml", gconv.Bytes(data), safe...) } -func doLoadContent(dataType string, data []byte, unsafe ...bool) (*Json, error) { +func doLoadContent(dataType string, data []byte, safe ...bool) (*Json, error) { var err error var result interface{} if len(data) == 0 { - return New(nil, unsafe...), nil + return New(nil, safe...), nil } if dataType == "" { dataType = checkDataType(data) @@ -194,15 +186,15 @@ func doLoadContent(dataType string, data []byte, unsafe ...bool) (*Json, error) return nil, fmt.Errorf(`json decoding failed for content: %s`, string(data)) } } - return New(result, unsafe...), nil + return New(result, safe...), nil } -func LoadContent(data interface{}, unsafe ...bool) (*Json, error) { +func LoadContent(data interface{}, safe ...bool) (*Json, error) { content := gconv.Bytes(data) if len(content) == 0 { - return New(nil, unsafe...), nil + return New(nil, safe...), nil } - return doLoadContent(checkDataType(content), content, unsafe...) + return doLoadContent(checkDataType(content), content, safe...) } diff --git a/g/encoding/gjson/gjson_z_unit_basic_test.go b/g/encoding/gjson/gjson_z_unit_basic_test.go index af2b9bc26..f9fe51b4a 100644 --- a/g/encoding/gjson/gjson_z_unit_basic_test.go +++ b/g/encoding/gjson/gjson_z_unit_basic_test.go @@ -24,18 +24,6 @@ func Test_New(t *testing.T) { }) } -func Test_NewUnsafe(t *testing.T) { - data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { - j := gjson.NewUnsafe(data) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) - }) -} - func Test_Valid(t *testing.T) { data1 := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data2 := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]`) diff --git a/g/encoding/gjson/gjson_z_unit_load_test.go b/g/encoding/gjson/gjson_z_unit_load_test.go index 97a8ade54..f411c4ae2 100644 --- a/g/encoding/gjson/gjson_z_unit_load_test.go +++ b/g/encoding/gjson/gjson_z_unit_load_test.go @@ -175,7 +175,7 @@ func Test_Load_TOML2(t *testing.T) { func Test_Load_Basic(t *testing.T) { gtest.Case(t, func() { - j := gjson.NewUnsafe() + j := gjson.New(nil) gtest.Assert(j.Value(), nil) _, err := gjson.Decode(nil) gtest.AssertNE(err, nil) diff --git a/g/encoding/gparser/gparser_api_new_load.go b/g/encoding/gparser/gparser_api_new_load.go index bca533485..91548f686 100644 --- a/g/encoding/gparser/gparser_api_new_load.go +++ b/g/encoding/gparser/gparser_api_new_load.go @@ -15,22 +15,14 @@ import ( // or it will make no sense. // The param specifies whether using this Parser object // in un-concurrent-safe context, which is false in default. -func New(value interface{}, unsafe ...bool) *Parser { - return &Parser{gjson.New(value, unsafe...)} -} - -// NewUnsafe creates a un-concurrent-safe Parser object. -func NewUnsafe(value ...interface{}) *Parser { - if len(value) > 0 { - return &Parser{gjson.New(value[0], false)} - } - return &Parser{gjson.New(nil, false)} +func New(value interface{}, safe ...bool) *Parser { + return &Parser{gjson.New(value, safe...)} } // Load loads content from specified file , // and creates a Parser object from its content. -func Load(path string, unsafe ...bool) (*Parser, error) { - if j, e := gjson.Load(path, unsafe...); e == nil { +func Load(path string, safe ...bool) (*Parser, error) { + if j, e := gjson.Load(path, safe...); e == nil { return &Parser{j}, nil } else { return nil, e @@ -40,8 +32,8 @@ func Load(path string, unsafe ...bool) (*Parser, error) { // LoadContent creates a Parser object from given content, // it checks the data type of automatically, // supporting JSON, XML, YAML and TOML types of data. -func LoadContent(data interface{}, unsafe ...bool) (*Parser, error) { - if j, e := gjson.LoadContent(data, unsafe...); e == nil { +func LoadContent(data interface{}, safe ...bool) (*Parser, error) { + if j, e := gjson.LoadContent(data, safe...); e == nil { return &Parser{j}, nil } else { return nil, e diff --git a/g/encoding/gparser/gparser_unit_basic_test.go b/g/encoding/gparser/gparser_unit_basic_test.go index 484c8e5f7..fc2d2d9b3 100644 --- a/g/encoding/gparser/gparser_unit_basic_test.go +++ b/g/encoding/gparser/gparser_unit_basic_test.go @@ -28,7 +28,7 @@ func Test_New(t *testing.T) { func Test_NewUnsafe(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) gtest.Case(t, func() { - j := gparser.NewUnsafe(data) + j := gparser.New(data) gtest.Assert(j.Get("n"), "123456789") gtest.Assert(j.Get("m"), g.Map{"k": "v"}) gtest.Assert(j.Get("m.k"), "v") diff --git a/g/encoding/gparser/gparser_unit_load_test.go b/g/encoding/gparser/gparser_unit_load_test.go index 098831e73..4f15e667a 100644 --- a/g/encoding/gparser/gparser_unit_load_test.go +++ b/g/encoding/gparser/gparser_unit_load_test.go @@ -176,7 +176,7 @@ func Test_Load_TOML2(t *testing.T) { func Test_Load_Nil(t *testing.T) { gtest.Case(t, func() { - p := gparser.NewUnsafe() + p := gparser.New(nil) gtest.Assert(p.Value(), nil) file := "test22222.json" filePath := gfile.Pwd() + gfile.Separator + file diff --git a/g/frame/gins/gins.go b/g/frame/gins/gins.go index 1acbf8c14..07c29cfba 100644 --- a/g/frame/gins/gins.go +++ b/g/frame/gins/gins.go @@ -29,7 +29,7 @@ const ( ) // 单例对象存储器 -var instances = gmap.NewStrAnyMap() +var instances = gmap.NewStrAnyMap(true) // 获取单例对象 func Get(key string) interface{} { diff --git a/g/g_func.go b/g/g_func.go index ea5ac080f..fad571235 100644 --- a/g/g_func.go +++ b/g/g_func.go @@ -14,8 +14,8 @@ import ( ) // NewVar returns a *gvar.Var. -func NewVar(i interface{}, unsafe ...bool) *Var { - return gvar.New(i, unsafe...) +func NewVar(i interface{}, safe ...bool) *Var { + return gvar.New(i, safe...) } // Wait blocks until all the web servers shutdown. diff --git a/g/internal/cmdenv/cmdenv.go b/g/internal/cmdenv/cmdenv.go index 89c06e562..242eaa654 100644 --- a/g/internal/cmdenv/cmdenv.go +++ b/g/internal/cmdenv/cmdenv.go @@ -54,5 +54,5 @@ func Get(key string, def ...interface{}) *gvar.Var { value = v } } - return gvar.New(value, true) + return gvar.New(value) } diff --git a/g/internal/mutex/mutex.go b/g/internal/mutex/mutex.go index eb347fd88..98a9d30a3 100644 --- a/g/internal/mutex/mutex.go +++ b/g/internal/mutex/mutex.go @@ -15,12 +15,15 @@ type Mutex struct { safe bool } -func New(unsafe ...bool) *Mutex { +// New creates and returns a new *Mutex. +// The parameter is used to specify whether using this mutex in concurrent-safety, +// which is false in default. +func New(safe ...bool) *Mutex { mu := new(Mutex) - if len(unsafe) > 0 { - mu.safe = !unsafe[0] + if len(safe) > 0 { + mu.safe = safe[0] } else { - mu.safe = true + mu.safe = false } return mu } @@ -29,14 +32,14 @@ func (mu *Mutex) IsSafe() bool { return mu.safe } -func (mu *Mutex) Lock(force ...bool) { - if mu.safe || (len(force) > 0 && force[0]) { +func (mu *Mutex) Lock() { + if mu.safe { mu.Mutex.Lock() } } -func (mu *Mutex) Unlock(force ...bool) { - if mu.safe || (len(force) > 0 && force[0]) { +func (mu *Mutex) Unlock() { + if mu.safe { mu.Mutex.Unlock() } } diff --git a/g/internal/mutex/mutex_z_unit_test.go b/g/internal/mutex/mutex_z_unit_test.go index ca7f0c368..c2f8a7a40 100644 --- a/g/internal/mutex/mutex_z_unit_test.go +++ b/g/internal/mutex/mutex_z_unit_test.go @@ -39,7 +39,7 @@ func TestMutexIsSafe(t *testing.T) { func TestSafeMutex(t *testing.T) { gtest.Case(t, func() { safeLock := mutex.New(false) - array := garray.New() + array := garray.New(true) go func() { safeLock.Lock() @@ -70,7 +70,7 @@ func TestSafeMutex(t *testing.T) { func TestUnsafeMutex(t *testing.T) { gtest.Case(t, func() { unsafeLock := mutex.New(true) - array := garray.New() + array := garray.New(true) go func() { unsafeLock.Lock() diff --git a/g/internal/rwmutex/rwmutex.go b/g/internal/rwmutex/rwmutex.go index 71aa7e9d2..ecf2c45bf 100644 --- a/g/internal/rwmutex/rwmutex.go +++ b/g/internal/rwmutex/rwmutex.go @@ -15,12 +15,15 @@ type RWMutex struct { safe bool } -func New(unsafe ...bool) *RWMutex { +// New creates and returns a new *RWMutex. +// The parameter is used to specify whether using this mutex in concurrent-safety, +// which is false in default. +func New(safe ...bool) *RWMutex { mu := new(RWMutex) - if len(unsafe) > 0 { - mu.safe = !unsafe[0] + if len(safe) > 0 { + mu.safe = safe[0] } else { - mu.safe = true + mu.safe = false } return mu } diff --git a/g/internal/rwmutex/rwmutex_z_unit_test.go b/g/internal/rwmutex/rwmutex_z_unit_test.go index 2c5cccbc1..1115abe56 100644 --- a/g/internal/rwmutex/rwmutex_z_unit_test.go +++ b/g/internal/rwmutex/rwmutex_z_unit_test.go @@ -39,7 +39,7 @@ func TestRwmutexIsSafe(t *testing.T) { func TestSafeRwmutex(t *testing.T) { gtest.Case(t, func() { safeLock := rwmutex.New() - array := garray.New() + array := garray.New(true) go func() { safeLock.Lock() @@ -70,7 +70,7 @@ func TestSafeRwmutex(t *testing.T) { func TestSafeReaderRwmutex(t *testing.T) { gtest.Case(t, func() { safeLock := rwmutex.New() - array := garray.New() + array := garray.New(true) go func() { safeLock.RLock() @@ -109,7 +109,7 @@ func TestSafeReaderRwmutex(t *testing.T) { func TestUnsafeRwmutex(t *testing.T) { gtest.Case(t, func() { unsafeLock := rwmutex.New(true) - array := garray.New() + array := garray.New(true) go func() { unsafeLock.Lock() diff --git a/g/net/ghttp/ghttp_request_params.go b/g/net/ghttp/ghttp_request_params.go index 7e258df01..c2f80beff 100644 --- a/g/net/ghttp/ghttp_request_params.go +++ b/g/net/ghttp/ghttp_request_params.go @@ -20,11 +20,11 @@ func (r *Request) SetParam(key string, value interface{}) { func (r *Request) GetParam(key string, def ...interface{}) *gvar.Var { if r.params != nil { if v, ok := r.params[key]; ok { - return gvar.New(v, true) + return gvar.New(v) } } if len(def) > 0 { - return gvar.New(def[0], true) + return gvar.New(def[0]) } - return gvar.New(nil, true) + return gvar.New(nil) } diff --git a/g/net/ghttp/ghttp_request_post.go b/g/net/ghttp/ghttp_request_post.go index 64345a858..9103a4b50 100644 --- a/g/net/ghttp/ghttp_request_post.go +++ b/g/net/ghttp/ghttp_request_post.go @@ -45,7 +45,7 @@ func (r *Request) GetPost(key string, def ...interface{}) []string { } func (r *Request) GetPostVar(key string, def ...interface{}) *gvar.Var { - return gvar.New(r.GetPostString(key, def...), true) + return gvar.New(r.GetPostString(key, def...)) } func (r *Request) GetPostString(key string, def ...interface{}) string { diff --git a/g/net/ghttp/ghttp_request_query.go b/g/net/ghttp/ghttp_request_query.go index 565c82a0d..099af9016 100644 --- a/g/net/ghttp/ghttp_request_query.go +++ b/g/net/ghttp/ghttp_request_query.go @@ -57,7 +57,7 @@ func (r *Request) GetQuery(key string, def ...interface{}) []string { } func (r *Request) GetQueryVar(key string, def ...interface{}) *gvar.Var { - return gvar.New(r.GetQueryString(key, def...), true) + return gvar.New(r.GetQueryString(key, def...)) } func (r *Request) GetQueryString(key string, def ...interface{}) string { diff --git a/g/net/ghttp/ghttp_request_request.go b/g/net/ghttp/ghttp_request_request.go index e8386e2ad..1ce6c03c9 100644 --- a/g/net/ghttp/ghttp_request_request.go +++ b/g/net/ghttp/ghttp_request_request.go @@ -30,9 +30,9 @@ func (r *Request) GetRequest(key string, def ...interface{}) []string { func (r *Request) GetRequestVar(key string, def ...interface{}) *gvar.Var { value := r.GetRequest(key, def...) if value != nil { - return gvar.New(value[0], true) + return gvar.New(value[0]) } - return gvar.New(nil, true) + return gvar.New(nil) } func (r *Request) GetRequestString(key string, def ...interface{}) string { diff --git a/g/net/ghttp/ghttp_server.go b/g/net/ghttp/ghttp_server.go index f67e0fc68..68cbbc072 100644 --- a/g/net/ghttp/ghttp_server.go +++ b/g/net/ghttp/ghttp_server.go @@ -125,7 +125,7 @@ var ( methodsMap = make(map[string]struct{}) // WebServer表,用以存储和检索名称与Server对象之间的关联关系 - serverMapping = gmap.NewStrAnyMap() + serverMapping = gmap.NewStrAnyMap(true) // 正常运行的WebServer数量,如果没有运行、失败或者全部退出,那么该值为0 serverRunning = gtype.NewInt() @@ -342,7 +342,7 @@ func (s *Server) GetRouteMap() string { } } return r - }, false) + }) } m[item.domain].Add(item) } diff --git a/g/net/ghttp/ghttp_server_config_static.go b/g/net/ghttp/ghttp_server_config_static.go index fd72c4205..9981f6f17 100644 --- a/g/net/ghttp/ghttp_server_config_static.go +++ b/g/net/ghttp/ghttp_server_config_static.go @@ -106,7 +106,7 @@ func (s *Server) AddStaticPath(prefix string, path string) { r = strings.Compare(s1, s2) } return r - }, false) + }) for _, v := range s.config.StaticPaths { array.Add(v.prefix) } diff --git a/g/net/ghttp/ghttp_server_router_hook.go b/g/net/ghttp/ghttp_server_router_hook.go index f3ee112d7..442533077 100644 --- a/g/net/ghttp/ghttp_server_router_hook.go +++ b/g/net/ghttp/ghttp_server_router_hook.go @@ -162,7 +162,7 @@ func (s *Server) searchHookHandler(method, path, domain, hook string) []*handler } // 多层链表遍历检索,从数组末尾的链表开始遍历,末尾的深度高优先级也高 - pushedSet := gset.NewStringSet(true) + pushedSet := gset.NewStringSet() for i := len(lists) - 1; i >= 0; i-- { for e := lists[i].Front(); e != nil; e = e.Next() { handler := e.Value.(*handlerItem) diff --git a/g/net/ghttp/ghttp_server_session.go b/g/net/ghttp/ghttp_server_session.go index 01fc03dd5..4afa99be7 100644 --- a/g/net/ghttp/ghttp_server_session.go +++ b/g/net/ghttp/ghttp_server_session.go @@ -57,7 +57,7 @@ func (s *Session) init() { } // 否则执行初始化创建 s.id = s.request.Cookie.MakeSessionId() - s.data = gmap.NewStrAnyMap() + s.data = gmap.NewStrAnyMap(true) s.server.sessions.Set(s.id, s.data, s.server.GetSessionMaxAge()*1000) } } @@ -114,7 +114,7 @@ func (s *Session) Get(key string, def ...interface{}) interface{} { // 获取SESSION,建议都用该方法获取参数 func (s *Session) GetVar(key string, def ...interface{}) *gvar.Var { - return gvar.New(s.Get(key, def...), true) + return gvar.New(s.Get(key, def...)) } // 删除session diff --git a/g/net/ghttp/ghttp_unit_init_test.go b/g/net/ghttp/ghttp_unit_init_test.go index 1e2933779..3952032e0 100644 --- a/g/net/ghttp/ghttp_unit_init_test.go +++ b/g/net/ghttp/ghttp_unit_init_test.go @@ -13,7 +13,7 @@ import ( var ( // 用于测试的端口数组,随机获取 - ports = garray.NewIntArray() + ports = garray.NewIntArray(true) ) func init() { diff --git a/g/net/gtcp/gtcp_pool.go b/g/net/gtcp/gtcp_pool.go index a1a0e2050..ccb5ce2b6 100644 --- a/g/net/gtcp/gtcp_pool.go +++ b/g/net/gtcp/gtcp_pool.go @@ -31,7 +31,7 @@ const ( var ( // 连接池对象map,键名为地址端口,键值为对应的连接池对象 - pools = gmap.NewStrAnyMap() + pools = gmap.NewStrAnyMap(true) ) // 创建TCP链接池对象 diff --git a/g/net/gtcp/gtcp_server.go b/g/net/gtcp/gtcp_server.go index 1fe42377b..e299fae30 100644 --- a/g/net/gtcp/gtcp_server.go +++ b/g/net/gtcp/gtcp_server.go @@ -28,7 +28,7 @@ type Server struct { } // Map for name to server, for singleton purpose. -var serverMapping = gmap.NewStrAnyMap() +var serverMapping = gmap.NewStrAnyMap(true) // GetServer returns the TCP server with specified , // or it returns a new normal TCP server named if it does not exist. diff --git a/g/net/gudp/gudp_server.go b/g/net/gudp/gudp_server.go index e0d7733e2..0bbe65907 100644 --- a/g/net/gudp/gudp_server.go +++ b/g/net/gudp/gudp_server.go @@ -26,7 +26,7 @@ type Server struct { } // Server表,用以存储和检索名称与Server对象之间的关联关系 -var serverMapping = gmap.NewStrAnyMap() +var serverMapping = gmap.NewStrAnyMap(true) // 获取/创建一个空配置的UDP Server // 单例模式,请保证name的唯一性 diff --git a/g/os/gcache/gcache_mem_cache.go b/g/os/gcache/gcache_mem_cache.go index 35f81cf75..982f62169 100644 --- a/g/os/gcache/gcache_mem_cache.go +++ b/g/os/gcache/gcache_mem_cache.go @@ -61,11 +61,11 @@ const ( // newMemCache creates and returns a new memory cache object. func newMemCache(lruCap ...int) *memCache { c := &memCache{ - lruGetList: glist.New(), + lruGetList: glist.New(true), data: make(map[interface{}]memCacheItem), expireTimes: make(map[interface{}]int64), expireSets: make(map[int64]*gset.Set), - eventList: glist.New(), + eventList: glist.New(true), closed: gtype.NewBool(), } if len(lruCap) > 0 { @@ -92,7 +92,7 @@ func (c *memCache) getExpireSet(expire int64) (expireSet *gset.Set) { // It creates and returns a new set for if it does not exist. func (c *memCache) getOrNewExpireSet(expire int64) (expireSet *gset.Set) { if expireSet = c.getExpireSet(expire); expireSet == nil { - expireSet = gset.New() + expireSet = gset.New(true) c.expireSetMu.Lock() if es, ok := c.expireSets[expire]; ok { expireSet = es diff --git a/g/os/gcache/gcache_mem_cache_lru.go b/g/os/gcache/gcache_mem_cache_lru.go index f67319100..8dfb1a885 100644 --- a/g/os/gcache/gcache_mem_cache_lru.go +++ b/g/os/gcache/gcache_mem_cache_lru.go @@ -28,9 +28,9 @@ type memCacheLru struct { func newMemCacheLru(cache *memCache) *memCacheLru { lru := &memCacheLru{ cache: cache, - data: gmap.New(), - list: glist.New(), - rawList: glist.New(), + data: gmap.New(true), + list: glist.New(true), + rawList: glist.New(true), closed: gtype.NewBool(), } gtimer.AddSingleton(time.Second, lru.SyncAndClear) diff --git a/g/os/gcfg/gcfg.go b/g/os/gcfg/gcfg.go index 70c31fbe8..c1828fabd 100644 --- a/g/os/gcfg/gcfg.go +++ b/g/os/gcfg/gcfg.go @@ -48,8 +48,8 @@ func New(file ...string) *Config { } c := &Config{ name: gtype.NewString(name), - paths: garray.NewStringArray(), - jsons: gmap.NewStrAnyMap(), + paths: garray.NewStringArray(true), + jsons: gmap.NewStrAnyMap(true), vc: gtype.NewBool(), } // Customized dir path from env/cmd. @@ -276,7 +276,7 @@ func (c *Config) getJson(file ...string) *gjson.Json { } content = gfile.GetContents(filePath) } - if j, err := gjson.LoadContent(content); err == nil { + if j, err := gjson.LoadContent(content, true); err == nil { j.SetViolenceCheck(c.vc.Val()) // Add monitor for this configuration file, // any changes of this file will refresh its cache in Config object. @@ -315,9 +315,9 @@ func (c *Config) Get(pattern string, def ...interface{}) interface{} { func (c *Config) GetVar(pattern string, def ...interface{}) *gvar.Var { if j := c.getJson(); j != nil { - return gvar.New(j.Get(pattern, def...), true) + return gvar.New(j.Get(pattern, def...)) } - return gvar.New(nil, true) + return gvar.New(nil) } func (c *Config) Contains(pattern string) bool { diff --git a/g/os/gcfg/gcfg_config.go b/g/os/gcfg/gcfg_config.go index 126a3fb76..66bdd214d 100644 --- a/g/os/gcfg/gcfg_config.go +++ b/g/os/gcfg/gcfg_config.go @@ -10,7 +10,7 @@ import "github.com/gogf/gf/g/container/gmap" var ( // Customized configuration content. - configs = gmap.NewStrStrMap() + configs = gmap.NewStrStrMap(true) ) // SetContent sets customized configuration content for specified . diff --git a/g/os/gcfg/gcfg_instance.go b/g/os/gcfg/gcfg_instance.go index ae7c9f0e8..0ffb76423 100644 --- a/g/os/gcfg/gcfg_instance.go +++ b/g/os/gcfg/gcfg_instance.go @@ -17,7 +17,7 @@ const ( var ( // Instances map. - instances = gmap.NewStrAnyMap() + instances = gmap.NewStrAnyMap(true) ) // Instance returns an instance of Config with default settings. diff --git a/g/os/gcmd/gcmd_option.go b/g/os/gcmd/gcmd_option.go index c8894f91a..6cbbcf76e 100644 --- a/g/os/gcmd/gcmd_option.go +++ b/g/os/gcmd/gcmd_option.go @@ -28,5 +28,5 @@ func (c *gCmdOption) Get(key string, def ...string) string { // GetVar returns the option value as *gvar.Var object specified by , // if value does not exist, then returns as its default value. func (c *gCmdOption) GetVar(key string, def ...string) *gvar.Var { - return gvar.New(c.Get(key, def...), true) + return gvar.New(c.Get(key, def...)) } diff --git a/g/os/gcmd/gcmd_value.go b/g/os/gcmd/gcmd_value.go index b13847f83..26e9f520b 100644 --- a/g/os/gcmd/gcmd_value.go +++ b/g/os/gcmd/gcmd_value.go @@ -28,5 +28,5 @@ func (c *gCmdValue) Get(index int, def ...string) string { // GetVar returns value by index as *gvar.Var object, // if value does not exist, then returns as its default value. func (c *gCmdValue) GetVar(index int, def ...string) *gvar.Var { - return gvar.New(c.Get(index, def...), true) + return gvar.New(c.Get(index, def...)) } diff --git a/g/os/gcron/gcron_cron.go b/g/os/gcron/gcron_cron.go index b3b7994fb..dcfea1644 100644 --- a/g/os/gcron/gcron_cron.go +++ b/g/os/gcron/gcron_cron.go @@ -30,7 +30,7 @@ func New() *Cron { return &Cron{ idGen: gtype.NewInt64(), status: gtype.NewInt(STATUS_RUNNING), - entries: gmap.NewStrAnyMap(), + entries: gmap.NewStrAnyMap(true), logPath: gtype.NewString(), logLevel: gtype.NewInt(glog.LEVEL_PROD), } diff --git a/g/os/gcron/gcron_unit_1_test.go b/g/os/gcron/gcron_unit_1_test.go index 125fc2edc..9d842b137 100644 --- a/g/os/gcron/gcron_unit_1_test.go +++ b/g/os/gcron/gcron_unit_1_test.go @@ -18,7 +18,7 @@ import ( func TestCron_Add_Close(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) _, err1 := cron.Add("* * * * * *", func() { //glog.Println("cron1") array.Append(1) @@ -74,7 +74,7 @@ func TestCron_Basic(t *testing.T) { func TestCron_Remove(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.Add("* * * * * *", func() { array.Append(1) }, "add") @@ -110,7 +110,7 @@ func TestCron_AddSingleton(t *testing.T) { // keep this gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.AddSingleton("* * * * * *", func() { array.Append(1) time.Sleep(50 * time.Second) @@ -125,7 +125,7 @@ func TestCron_AddSingleton(t *testing.T) { func TestCron_AddOnce1(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.AddOnce("* * * * * *", func() { array.Append(1) }) @@ -142,7 +142,7 @@ func TestCron_AddOnce1(t *testing.T) { func TestCron_AddOnce2(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.AddOnce("@every 2s", func() { array.Append(1) }) @@ -156,7 +156,7 @@ func TestCron_AddOnce2(t *testing.T) { func TestCron_AddTimes(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.AddTimes("* * * * * *", 2, func() { array.Append(1) }) @@ -169,7 +169,7 @@ func TestCron_AddTimes(t *testing.T) { func TestCron_DelayAdd(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.DelayAdd(500*time.Millisecond, "* * * * * *", func() { array.Append(1) }) @@ -186,7 +186,7 @@ func TestCron_DelayAdd(t *testing.T) { func TestCron_DelayAddSingleton(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.DelayAddSingleton(500*time.Millisecond, "* * * * * *", func() { array.Append(1) time.Sleep(10 * time.Second) @@ -201,7 +201,7 @@ func TestCron_DelayAddSingleton(t *testing.T) { func TestCron_DelayAddOnce(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.DelayAddOnce(500*time.Millisecond, "* * * * * *", func() { array.Append(1) }) @@ -218,7 +218,7 @@ func TestCron_DelayAddOnce(t *testing.T) { func TestCron_DelayAddTimes(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.DelayAddTimes(500*time.Millisecond, "* * * * * *", 2, func() { array.Append(1) }) diff --git a/g/os/gcron/gcron_unit_2_test.go b/g/os/gcron/gcron_unit_2_test.go index e07b5cfca..fa4631625 100644 --- a/g/os/gcron/gcron_unit_2_test.go +++ b/g/os/gcron/gcron_unit_2_test.go @@ -20,7 +20,7 @@ func TestCron_Entry_Operations(t *testing.T) { gtest.Case(t, func() { cron := gcron.New() - array := garray.New() + array := garray.New(true) cron.DelayAddTimes(500*time.Millisecond, "* * * * * *", 2, func() { glog.Println("add times") array.Append(1) @@ -35,7 +35,7 @@ func TestCron_Entry_Operations(t *testing.T) { }) cron := gcron.New() - array := garray.New() + array := garray.New(true) entry, err1 := cron.Add("* * * * * *", func() { glog.Println("add") array.Append(1) diff --git a/g/os/gfile/gfile_search.go b/g/os/gfile/gfile_search.go index 5d11547ea..9785a98ee 100644 --- a/g/os/gfile/gfile_search.go +++ b/g/os/gfile/gfile_search.go @@ -24,7 +24,7 @@ func Search(name string, prioritySearchPaths ...string) (realPath string, err er } // TODO move search paths to internal package variable. // Search paths array. - array := garray.NewStringArray(true) + array := garray.NewStringArray() array.Append(prioritySearchPaths...) array.Append(Pwd(), SelfDir()) if path := MainPkgPath(); path != "" { diff --git a/g/os/gflock/gflock_unit_test.go b/g/os/gflock/gflock_unit_test.go index 689f0a921..761071879 100644 --- a/g/os/gflock/gflock_unit_test.go +++ b/g/os/gflock/gflock_unit_test.go @@ -43,7 +43,7 @@ func Test_GFlock_Base(t *testing.T) { func Test_GFlock_Lock(t *testing.T) { gtest.Case(t, func() { fileName := "testLock" - array := garray.New() + array := garray.New(true) lock := gflock.New(fileName) lock2 := gflock.New(fileName) @@ -73,7 +73,7 @@ func Test_GFlock_Lock(t *testing.T) { func Test_GFlock_RLock(t *testing.T) { gtest.Case(t, func() { fileName := "testRLock" - array := garray.New() + array := garray.New(true) lock := gflock.New(fileName) lock2 := gflock.New(fileName) @@ -101,7 +101,7 @@ func Test_GFlock_RLock(t *testing.T) { func Test_GFlock_TryLock(t *testing.T) { gtest.Case(t, func() { fileName := "testTryLock" - array := garray.New() + array := garray.New(true) lock := gflock.New(fileName) lock2 := gflock.New(fileName) @@ -139,7 +139,7 @@ func Test_GFlock_TryLock(t *testing.T) { func Test_GFlock_TryRLock(t *testing.T) { gtest.Case(t, func() { fileName := "testTryRLock" - array := garray.New() + array := garray.New(true) lock := gflock.New(fileName) lock2 := gflock.New(fileName) go func() { diff --git a/g/os/gfpool/gfpool.go b/g/os/gfpool/gfpool.go index 38d9fa70b..c19eb32db 100644 --- a/g/os/gfpool/gfpool.go +++ b/g/os/gfpool/gfpool.go @@ -38,7 +38,7 @@ type File struct { var ( // 全局文件指针池Map, 不过期 - pools = gmap.NewStrAnyMap() + pools = gmap.NewStrAnyMap(true) ) // 获得文件对象,并自动创建指针池(过期时间单位:毫秒) diff --git a/g/os/gfsnotify/gfsnotify.go b/g/os/gfsnotify/gfsnotify.go index c51ec0041..08b1f860a 100644 --- a/g/os/gfsnotify/gfsnotify.go +++ b/g/os/gfsnotify/gfsnotify.go @@ -70,7 +70,7 @@ var ( // 默认的watchers是否初始化,使用时才创建 watcherInited = gtype.NewBool() // 回调方法ID与对象指针的映射哈希表,用于根据ID快速查找回调对象 - callbackIdMap = gmap.NewIntAnyMap() + callbackIdMap = gmap.NewIntAnyMap(true) // 回调函数的ID生成器(原子操作) callbackIdGenerator = gtype.NewInt() ) @@ -81,7 +81,7 @@ func New() (*Watcher, error) { cache: gcache.New(), events: gqueue.New(), closeChan: make(chan struct{}), - callbacks: gmap.NewStrAnyMap(), + callbacks: gmap.NewStrAnyMap(true), } if watcher, err := fsnotify.NewWatcher(); err == nil { w.watcher = watcher diff --git a/g/os/gfsnotify/gfsnotify_watcher.go b/g/os/gfsnotify/gfsnotify_watcher.go index ddd12bc35..257d4f812 100644 --- a/g/os/gfsnotify/gfsnotify_watcher.go +++ b/g/os/gfsnotify/gfsnotify_watcher.go @@ -56,7 +56,7 @@ func (w *Watcher) addWithCallbackFunc(path string, callbackFunc func(event *Even w.callbacks.LockFunc(func(m map[string]interface{}) { list := (*glist.List)(nil) if v, ok := m[path]; !ok { - list = glist.New() + list = glist.New(true) m[path] = list } else { list = v.(*glist.List) diff --git a/g/os/gmlock/gmlock_locker.go b/g/os/gmlock/gmlock_locker.go index ce00c132d..3e9c7b719 100644 --- a/g/os/gmlock/gmlock_locker.go +++ b/g/os/gmlock/gmlock_locker.go @@ -22,7 +22,7 @@ type Locker struct { // A memory locker can lock/unlock with dynamic string key. func New() *Locker { return &Locker{ - m: gmap.NewStrAnyMap(), + m: gmap.NewStrAnyMap(true), } } diff --git a/g/os/gmlock/gmlock_unit_lock_test.go b/g/os/gmlock/gmlock_unit_lock_test.go index da1132d4b..8bd7bbdda 100644 --- a/g/os/gmlock/gmlock_unit_lock_test.go +++ b/g/os/gmlock/gmlock_unit_lock_test.go @@ -18,7 +18,7 @@ import ( func Test_Locker_Lock(t *testing.T) { gtest.Case(t, func() { key := "testLock" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -42,7 +42,7 @@ func Test_Locker_Lock(t *testing.T) { gtest.Case(t, func() { key := "testLock" - array := garray.New() + array := garray.New(true) lock := gmlock.New() go func() { lock.Lock(key) @@ -70,7 +70,7 @@ func Test_Locker_Lock(t *testing.T) { func Test_Locker_TryLock(t *testing.T) { gtest.Case(t, func() { key := "testTryLock" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -105,7 +105,7 @@ func Test_Locker_LockFunc(t *testing.T) { //no expire gtest.Case(t, func() { key := "testLockFunc" - array := garray.New() + array := garray.New(true) go func() { gmlock.LockFunc(key, func() { array.Append(1) @@ -130,7 +130,7 @@ func Test_Locker_TryLockFunc(t *testing.T) { //no expire gtest.Case(t, func() { key := "testTryLockFunc" - array := garray.New() + array := garray.New(true) go func() { gmlock.TryLockFunc(key, func() { array.Append(1) diff --git a/g/os/gmlock/gmlock_unit_rlock_test.go b/g/os/gmlock/gmlock_unit_rlock_test.go index 3b8b299f5..1f017f7a1 100644 --- a/g/os/gmlock/gmlock_unit_rlock_test.go +++ b/g/os/gmlock/gmlock_unit_rlock_test.go @@ -19,7 +19,7 @@ func Test_Locker_RLock(t *testing.T) { //RLock before Lock gtest.Case(t, func() { key := "testRLockBeforeLock" - array := garray.New() + array := garray.New(true) go func() { gmlock.RLock(key) array.Append(1) @@ -41,7 +41,7 @@ func Test_Locker_RLock(t *testing.T) { //Lock before RLock gtest.Case(t, func() { key := "testLockBeforeRLock" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -63,7 +63,7 @@ func Test_Locker_RLock(t *testing.T) { //Lock before RLocks gtest.Case(t, func() { key := "testLockBeforeRLocks" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -95,7 +95,7 @@ func Test_Locker_TryRLock(t *testing.T) { //Lock before TryRLock gtest.Case(t, func() { key := "testLockBeforeTryRLock" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -118,7 +118,7 @@ func Test_Locker_TryRLock(t *testing.T) { //Lock before TryRLocks gtest.Case(t, func() { key := "testLockBeforeTryRLocks" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -150,7 +150,7 @@ func Test_Locker_RLockFunc(t *testing.T) { //RLockFunc before Lock gtest.Case(t, func() { key := "testRLockFuncBeforeLock" - array := garray.New() + array := garray.New(true) go func() { gmlock.RLockFunc(key, func() { array.Append(1) @@ -172,7 +172,7 @@ func Test_Locker_RLockFunc(t *testing.T) { //Lock before RLockFunc gtest.Case(t, func() { key := "testLockBeforeRLockFunc" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -194,7 +194,7 @@ func Test_Locker_RLockFunc(t *testing.T) { //Lock before RLockFuncs gtest.Case(t, func() { key := "testLockBeforeRLockFuncs" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -226,7 +226,7 @@ func Test_Locker_TryRLockFunc(t *testing.T) { //Lock before TryRLockFunc gtest.Case(t, func() { key := "testLockBeforeTryRLockFunc" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) @@ -248,7 +248,7 @@ func Test_Locker_TryRLockFunc(t *testing.T) { //Lock before TryRLockFuncs gtest.Case(t, func() { key := "testLockBeforeTryRLockFuncs" - array := garray.New() + array := garray.New(true) go func() { gmlock.Lock(key) array.Append(1) diff --git a/g/os/gmutex/gmutex_unit_test.go b/g/os/gmutex/gmutex_unit_test.go index 74d42edb1..709079944 100644 --- a/g/os/gmutex/gmutex_unit_test.go +++ b/g/os/gmutex/gmutex_unit_test.go @@ -91,7 +91,7 @@ func Test_Mutex_IsLocked(t *testing.T) { func Test_Mutex_Unlock(t *testing.T) { gtest.Case(t, func() { mu := gmutex.New() - array := garray.New() + array := garray.New(true) go func() { mu.LockFunc(func() { array.Append(1) @@ -129,7 +129,7 @@ func Test_Mutex_Unlock(t *testing.T) { func Test_Mutex_LockFunc(t *testing.T) { gtest.Case(t, func() { mu := gmutex.New() - array := garray.New() + array := garray.New(true) go func() { mu.LockFunc(func() { array.Append(1) @@ -154,7 +154,7 @@ func Test_Mutex_LockFunc(t *testing.T) { func Test_Mutex_TryLockFunc(t *testing.T) { gtest.Case(t, func() { mu := gmutex.New() - array := garray.New() + array := garray.New(true) go func() { mu.LockFunc(func() { array.Append(1) @@ -185,7 +185,7 @@ func Test_Mutex_TryLockFunc(t *testing.T) { func Test_Mutex_RLockFunc(t *testing.T) { gtest.Case(t, func() { mu := gmutex.New() - array := garray.New() + array := garray.New(true) go func() { mu.LockFunc(func() { array.Append(1) @@ -209,7 +209,7 @@ func Test_Mutex_RLockFunc(t *testing.T) { gtest.Case(t, func() { mu := gmutex.New() - array := garray.New() + array := garray.New(true) go func() { time.Sleep(100 * time.Millisecond) mu.RLockFunc(func() { @@ -240,7 +240,7 @@ func Test_Mutex_RLockFunc(t *testing.T) { func Test_Mutex_TryRLockFunc(t *testing.T) { gtest.Case(t, func() { mu := gmutex.New() - array := garray.New() + array := garray.New(true) go func() { mu.LockFunc(func() { array.Append(1) diff --git a/g/os/gproc/gproc_comm.go b/g/os/gproc/gproc_comm.go index fdd955946..5402de948 100644 --- a/g/os/gproc/gproc_comm.go +++ b/g/os/gproc/gproc_comm.go @@ -23,10 +23,10 @@ type Msg struct { } // 本地进程通信接收消息队列(按照分组进行构建的map,键值为*gqueue.Queue对象) -var commReceiveQueues = gmap.NewStrAnyMap() +var commReceiveQueues = gmap.NewStrAnyMap(true) // (用于发送)已建立的PID对应的Conn通信对象,键值为一个Pool,防止并行使用同一个通信对象造成数据重叠 -var commPidConnMap = gmap.NewIntAnyMap() +var commPidConnMap = gmap.NewIntAnyMap(true) // 获取指定进程的通信文件地址 func getCommFilePath(pid int) string { diff --git a/g/os/gproc/gproc_manager.go b/g/os/gproc/gproc_manager.go index 8ab2cb701..ad6158fbe 100644 --- a/g/os/gproc/gproc_manager.go +++ b/g/os/gproc/gproc_manager.go @@ -20,7 +20,7 @@ type Manager struct { // 创建一个进程管理器 func NewManager() *Manager { return &Manager{ - processes: gmap.NewIntAnyMap(), + processes: gmap.NewIntAnyMap(true), } } diff --git a/g/os/grpool/grpool.go b/g/os/grpool/grpool.go index bb12a265d..27d443f1e 100644 --- a/g/os/grpool/grpool.go +++ b/g/os/grpool/grpool.go @@ -32,7 +32,7 @@ func New(limit ...int) *Pool { p := &Pool{ limit: -1, count: gtype.NewInt(), - list: glist.New(), + list: glist.New(true), closed: gtype.NewBool(), } if len(limit) > 0 && limit[0] > 0 { diff --git a/g/os/gspath/gspath.go b/g/os/gspath/gspath.go index e9555a9f6..31e2161a3 100644 --- a/g/os/gspath/gspath.go +++ b/g/os/gspath/gspath.go @@ -37,17 +37,17 @@ type SPathCacheItem struct { var ( // 单个目录路径对应的SPath对象指针,用于路径检索对象复用 - pathsMap = gmap.NewStrAnyMap() - pathsCacheMap = gmap.NewStrAnyMap() + pathsMap = gmap.NewStrAnyMap(true) + pathsCacheMap = gmap.NewStrAnyMap(true) ) // 创建一个搜索对象 func New(path string, cache bool) *SPath { sp := &SPath{ - paths: garray.NewStringArray(), + paths: garray.NewStringArray(true), } if cache { - sp.cache = gmap.NewStrStrMap() + sp.cache = gmap.NewStrStrMap(true) } if len(path) > 0 { if _, err := sp.Add(path); err != nil { diff --git a/g/os/gtimer/gtimer_timer.go b/g/os/gtimer/gtimer_timer.go index a8d2322da..a5a8c857a 100644 --- a/g/os/gtimer/gtimer_timer.go +++ b/g/os/gtimer/gtimer_timer.go @@ -73,7 +73,7 @@ func (t *Timer) newWheel(level int, slot int, interval time.Duration) *wheel { intervalMs: interval.Nanoseconds() / 1e6, } for i := int64(0); i < w.number; i++ { - w.slots[i] = glist.New() + w.slots[i] = glist.New(true) } return w } diff --git a/g/os/gtimer/gtimer_z_unit_0_test.go b/g/os/gtimer/gtimer_z_unit_0_test.go index db8db62ef..924bfcf9e 100644 --- a/g/os/gtimer/gtimer_z_unit_0_test.go +++ b/g/os/gtimer/gtimer_z_unit_0_test.go @@ -18,7 +18,7 @@ import ( func TestSetTimeout(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.SetTimeout(200*time.Millisecond, func() { array.Append(1) }) @@ -29,7 +29,7 @@ func TestSetTimeout(t *testing.T) { func TestSetInterval(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.SetInterval(200*time.Millisecond, func() { array.Append(1) }) @@ -40,7 +40,7 @@ func TestSetInterval(t *testing.T) { func TestAddEntry(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.AddEntry(200*time.Millisecond, func() { array.Append(1) }, false, 2, gtimer.STATUS_READY) @@ -51,7 +51,7 @@ func TestAddEntry(t *testing.T) { func TestAddSingleton(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.AddSingleton(200*time.Millisecond, func() { array.Append(1) time.Sleep(10000 * time.Millisecond) @@ -63,7 +63,7 @@ func TestAddSingleton(t *testing.T) { func TestAddTimes(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.AddTimes(200*time.Millisecond, 2, func() { array.Append(1) }) @@ -74,7 +74,7 @@ func TestAddTimes(t *testing.T) { func TestDelayAdd(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.DelayAdd(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }) @@ -87,7 +87,7 @@ func TestDelayAdd(t *testing.T) { func TestDelayAddEntry(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.DelayAddEntry(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }, false, 2, gtimer.STATUS_READY) @@ -100,7 +100,7 @@ func TestDelayAddEntry(t *testing.T) { func TestDelayAddSingleton(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.DelayAddSingleton(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) time.Sleep(10000 * time.Millisecond) @@ -114,7 +114,7 @@ func TestDelayAddSingleton(t *testing.T) { func TestDelayAddOnce(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.DelayAddOnce(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }) @@ -127,7 +127,7 @@ func TestDelayAddOnce(t *testing.T) { func TestDelayAddTimes(t *testing.T) { gtest.Case(t, func() { - array := garray.New() + array := garray.New(true) gtimer.DelayAddTimes(200*time.Millisecond, 200*time.Millisecond, 2, func() { array.Append(1) }) diff --git a/g/os/gtimer/gtimer_z_unit_1_test.go b/g/os/gtimer/gtimer_z_unit_1_test.go index d8a708eae..e0b2c09c6 100644 --- a/g/os/gtimer/gtimer_z_unit_1_test.go +++ b/g/os/gtimer/gtimer_z_unit_1_test.go @@ -23,7 +23,7 @@ func New() *gtimer.Timer { func TestTimer_Add_Close(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) //fmt.Println("start", time.Now()) timer.Add(200*time.Millisecond, func() { //fmt.Println("entry1", time.Now()) @@ -52,7 +52,7 @@ func TestTimer_Add_Close(t *testing.T) { func TestTimer_Start_Stop_Close(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.Add(200*time.Millisecond, func() { //glog.Println("add...") array.Append(1) @@ -75,7 +75,7 @@ func TestTimer_Start_Stop_Close(t *testing.T) { func TestTimer_AddSingleton(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.AddSingleton(200*time.Millisecond, func() { array.Append(1) time.Sleep(10 * time.Second) @@ -91,7 +91,7 @@ func TestTimer_AddSingleton(t *testing.T) { func TestTimer_AddOnce(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.AddOnce(200*time.Millisecond, func() { array.Append(1) }) @@ -113,7 +113,7 @@ func TestTimer_AddOnce(t *testing.T) { func TestTimer_AddTimes(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.AddTimes(200*time.Millisecond, 2, func() { array.Append(1) }) @@ -125,7 +125,7 @@ func TestTimer_AddTimes(t *testing.T) { func TestTimer_DelayAdd(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.DelayAdd(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }) @@ -139,7 +139,7 @@ func TestTimer_DelayAdd(t *testing.T) { func TestTimer_DelayAddEntry(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.DelayAddEntry(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }, false, 100, gtimer.STATUS_READY) @@ -153,7 +153,7 @@ func TestTimer_DelayAddEntry(t *testing.T) { func TestTimer_DelayAddSingleton(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.DelayAddSingleton(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) time.Sleep(10 * time.Second) @@ -169,7 +169,7 @@ func TestTimer_DelayAddSingleton(t *testing.T) { func TestTimer_DelayAddOnce(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.DelayAddOnce(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }) @@ -187,7 +187,7 @@ func TestTimer_DelayAddOnce(t *testing.T) { func TestTimer_DelayAddTimes(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.DelayAddTimes(200*time.Millisecond, 500*time.Millisecond, 2, func() { array.Append(1) }) @@ -208,7 +208,7 @@ func TestTimer_DelayAddTimes(t *testing.T) { func TestTimer_AddLessThanInterval(t *testing.T) { gtest.Case(t, func() { timer := gtimer.New(10, 100*time.Millisecond) - array := garray.New() + array := garray.New(true) timer.Add(20*time.Millisecond, func() { array.Append(1) }) @@ -226,7 +226,7 @@ func TestTimer_AddLessThanInterval(t *testing.T) { func TestTimer_AddLeveledEntry1(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) //glog.Println("start") timer.DelayAdd(1000*time.Millisecond, 1001*time.Millisecond, func() { //glog.Println("add") @@ -243,7 +243,7 @@ func TestTimer_AddLeveledEntry1(t *testing.T) { func TestTimer_Exit(t *testing.T) { gtest.Case(t, func() { timer := New() - array := garray.New() + array := garray.New(true) timer.Add(200*time.Millisecond, func() { array.Append(1) gtimer.Exit() diff --git a/g/os/gtimer/gtimer_z_unit_2_test.go b/g/os/gtimer/gtimer_z_unit_2_test.go index 35c158ca0..f6a02478d 100644 --- a/g/os/gtimer/gtimer_z_unit_2_test.go +++ b/g/os/gtimer/gtimer_z_unit_2_test.go @@ -18,7 +18,7 @@ import ( func TestEntry_Start_Stop_Close(t *testing.T) { timer := New() - array := garray.New() + array := garray.New(true) entry := timer.Add(200*time.Millisecond, func() { array.Append(1) }) @@ -39,7 +39,7 @@ func TestEntry_Start_Stop_Close(t *testing.T) { func TestEntry_Singleton(t *testing.T) { timer := New() - array := garray.New() + array := garray.New(true) entry := timer.Add(200*time.Millisecond, func() { array.Append(1) time.Sleep(10 * time.Second) @@ -56,7 +56,7 @@ func TestEntry_Singleton(t *testing.T) { func TestEntry_SetTimes(t *testing.T) { timer := New() - array := garray.New() + array := garray.New(true) entry := timer.Add(200*time.Millisecond, func() { array.Append(1) }) @@ -67,7 +67,7 @@ func TestEntry_SetTimes(t *testing.T) { func TestEntry_Run(t *testing.T) { timer := New() - array := garray.New() + array := garray.New(true) entry := timer.Add(1000*time.Millisecond, func() { array.Append(1) }) diff --git a/g/os/gview/gview.go b/g/os/gview/gview.go index 98d363380..a69a5ba94 100644 --- a/g/os/gview/gview.go +++ b/g/os/gview/gview.go @@ -57,7 +57,7 @@ func ParseContent(content string, params Params) (string, error) { // The parameter specifies the template directory path to load template files. func New(path ...string) *View { view := &View{ - paths: garray.NewStringArray(), + paths: garray.NewStringArray(true), data: make(map[string]interface{}), funcMap: make(map[string]interface{}), delimiters: make([]string, 2), diff --git a/g/os/gview/gview_doparse.go b/g/os/gview/gview_doparse.go index f959f2903..f5c3f3afa 100644 --- a/g/os/gview/gview_doparse.go +++ b/g/os/gview/gview_doparse.go @@ -31,7 +31,7 @@ const ( var ( // Templates cache map for template folder. // TODO Note that there's no expiring logic for this map. - templates = gmap.NewStrAnyMap() + templates = gmap.NewStrAnyMap(true) ) // getTemplate returns the template object associated with given template folder . diff --git a/g/os/gview/gview_instance.go b/g/os/gview/gview_instance.go index ebb075096..ddc644be2 100644 --- a/g/os/gview/gview_instance.go +++ b/g/os/gview/gview_instance.go @@ -15,7 +15,7 @@ const ( var ( // Instances map. - instances = gmap.NewStrAnyMap() + instances = gmap.NewStrAnyMap(true) ) // Instance returns an instance of View with default settings. diff --git a/g/util/gvalid/gvalid_check.go b/g/util/gvalid/gvalid_check.go index 00afec894..2c909636b 100644 --- a/g/util/gvalid/gvalid_check.go +++ b/g/util/gvalid/gvalid_check.go @@ -26,7 +26,7 @@ const ( var ( // 默认错误消息管理对象(并发安全) - errorMsgMap = gmap.NewStrStrMap() + errorMsgMap = gmap.NewStrStrMap(true) // 单规则正则对象,这里使用包内部变量存储,不需要多次解析 ruleRegex, _ = regexp.Compile(gSINGLE_RULE_PATTERN)