This commit is contained in:
aozhiwei 2020-09-10 11:24:57 +08:00
parent 6fd253d455
commit 88b284f7de
3 changed files with 52 additions and 4 deletions

View File

@ -1,13 +1,16 @@
package q5
import "io"
import "strings"
import "crypto/md5"
import "encoding/hex"
import "hash/crc32"
func Test()(a string) {
return "testb"
}
const (
JSON_NONE = 0
JSON_ARRAY = iota
JSON_OBJECT = iota
)
func Md5Str(data string) string {
h := md5.New()
@ -22,3 +25,23 @@ func Crc32(data string) uint32 {
code := ieee.Sum32()
return code
}
func JsonStrType(data string) int32 {
arrayIdx := strings.IndexByte(data, '[')
objectIdx := strings.IndexByte(data, '{')
if arrayIdx < 0 && objectIdx < 0 {
return JSON_NONE
} else {
if arrayIdx < 0 {
return JSON_OBJECT
}
if objectIdx < 0 {
return JSON_ARRAY
}
if arrayIdx < objectIdx {
return JSON_ARRAY
} else {
return JSON_OBJECT
}
}
}

View File

@ -62,3 +62,23 @@ func TraverseArray(arrayPtr interface{}, callback func(data interface{})) {
callback(val)
}
}
func IsNumberType(v interface{}) bool {
switch reflect.TypeOf(v).Kind() {
case
reflect.Int,
reflect.Int8,
reflect.Int16,
reflect.Int32,
reflect.Int64,
reflect.Uint8,
reflect.Uint16,
reflect.Uint32,
reflect.Uint64,
reflect.Float32,
reflect.Float64:
return true
default:
return false
}
}

View File

@ -335,9 +335,14 @@ func (this *Timer) newTimerList() *TimerList {
}
func (this *Timer) gcTimerFunc(params *XParams) {
for i := 0; !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum && i < 1000; i++ {
count := 0
for ; !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum; {
timerList := this.freeTimerList.FirstEntry().(*TimerList)
timerList.entry.DelInit()
this.freeTimerNum--
count++
if count > 1000 {
break
}
}
}