From 2c40cf2af18efeb9223893bdbcb273f2dea11275 Mon Sep 17 00:00:00 2001 From: "shuai.qi" Date: Wed, 29 Nov 2023 15:35:40 +0800 Subject: [PATCH] optimize: set slice cap --- cache.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cache.go b/cache.go index 0f4fa6b5..dcb18468 100644 --- a/cache.go +++ b/cache.go @@ -112,8 +112,6 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr return cs } - cs = &cStruct{name: sName, fields: make([]*cField, 0), fn: v.structLevelFuncs[typ]} - numFields := current.NumField() rules := v.rules[typ] @@ -122,6 +120,7 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr var tag string var customName string + cs = &cStruct{name: sName, fields: make([]*cField, 0, numFields), fn: v.structLevelFuncs[typ]} for i := 0; i < numFields; i++ { fld = typ.Field(i)