From 88b284f7de58d7740bf92c9b995c967c934df18e Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Sep 2020 11:24:57 +0800 Subject: [PATCH] 1 --- strutils.go | 29 ++++++++++++++++++++++++++--- sysutils.go | 20 ++++++++++++++++++++ timer.go | 7 ++++++- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/strutils.go b/strutils.go index fab4c2c..988f329 100644 --- a/strutils.go +++ b/strutils.go @@ -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 + } + } +} diff --git a/sysutils.go b/sysutils.go index 8c2b5aa..f35e5aa 100644 --- a/sysutils.go +++ b/sysutils.go @@ -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 + } +} diff --git a/timer.go b/timer.go index ecfcd17..55c4d9b 100644 --- a/timer.go +++ b/timer.go @@ -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 + } } }