diff --git a/sysutils.go b/sysutils.go index 7892d75..c08832a 100644 --- a/sysutils.go +++ b/sysutils.go @@ -33,19 +33,17 @@ func MkInt64(lo32 int32, hi32 int32) int64 { return int64(lo32) + (int64(hi32) << 32) } -/* -func Request(r *http.Request, name string) *XValue { +func Request(r *http.Request, name string) string { if r.Form == nil { r.ParseForm() } if vs, ok := r.Form[name]; ok { if len(vs) > 0 { - return NewXString(vs[0]) + return vs[0] } } - return NewXString("") + return "" } -*/ func Response(w* http.ResponseWriter, data string) { (*w).Write([]byte(data)) @@ -99,14 +97,6 @@ func ForceCreateDir(dir string) bool { return true } -func TraverseArray(arrayPtr interface{}, callback func(data interface{})) { - array := reflect.ValueOf(arrayPtr).Elem() - for i := 0; i < array.Len(); i++ { - val := array.Index(i).Addr().Interface() - callback(val) - } -} - func IsNumberType(v interface{}) bool { switch reflect.TypeOf(v).Kind() { case diff --git a/timer.go b/timer.go index ccc4b76..b32e909 100644 --- a/timer.go +++ b/timer.go @@ -38,16 +38,26 @@ func (this *XTimer) Init( context interface{}, gcTime int32, cacheTimerNum int32) { - initListHeadFunc := func (data interface{}) { - head := data.(*ListHead) + initListHeadFunc := func (head *ListHead) { head.Init(nil) } initListHeadFunc(&this.freeTimerList) - TraverseArray(&this.tv1, initListHeadFunc) - TraverseArray(&this.tv2, initListHeadFunc) - TraverseArray(&this.tv3, initListHeadFunc) - TraverseArray(&this.tv4, initListHeadFunc) - TraverseArray(&this.tv5, initListHeadFunc) + for i := 0; i < len(this.tv1); i++ { + initListHeadFunc(&this.tv1[i]) + } + for i := 0; i < len(this.tv2); i++ { + initListHeadFunc(&this.tv2[i]) + } + for i := 0; i < len(this.tv3); i++ { + initListHeadFunc(&this.tv3[i]) + } + for i := 0; i < len(this.tv4); i++ { + initListHeadFunc(&this.tv4[i]) + } + for i := 0; i < len(this.tv5); i++ { + initListHeadFunc(&this.tv5[i]) + } + this.timerTick = getTickCount(context) this.context = context this.getTickCount = getTickCount @@ -60,8 +70,7 @@ func (this *XTimer) UnInit() { } func (this *XTimer) clear() { - freeTimerFunc := func (data interface{}) { - head := data.(*ListHead) + freeTimerFunc := func (head *ListHead) { for !head.Empty() { timerList := head.FirstEntry().(*XTimerList) this.detachTimer(timerList) @@ -71,11 +80,21 @@ func (this *XTimer) clear() { } } freeTimerFunc(&this.freeTimerList) - TraverseArray(&this.tv1, freeTimerFunc) - TraverseArray(&this.tv2, freeTimerFunc) - TraverseArray(&this.tv3, freeTimerFunc) - TraverseArray(&this.tv4, freeTimerFunc) - TraverseArray(&this.tv5, freeTimerFunc) + for i := 0; i < len(this.tv1); i++ { + freeTimerFunc(&this.tv1[i]) + } + for i := 0; i < len(this.tv2); i++ { + freeTimerFunc(&this.tv2[i]) + } + for i := 0; i < len(this.tv3); i++ { + freeTimerFunc(&this.tv3[i]) + } + for i := 0; i < len(this.tv4); i++ { + freeTimerFunc(&this.tv4[i]) + } + for i := 0; i < len(this.tv5); i++ { + freeTimerFunc(&this.tv5[i]) + } } func (this *XTimer) Update() {