@@ -520,23 +520,8 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e
520520 return nil
521521 }
522522
523- // find cached tag
524- ctag , ok := v .tagCache .Get (tag )
525- if ! ok {
526- v .tagCache .lock .Lock ()
527-
528- // could have been multiple trying to access, but once first is done this ensures tag
529- // isn't parsed again.
530- ctag , ok = v .tagCache .Get (tag )
531- if ! ok {
532- ctag , _ = v .parseFieldTagsRecursive (tag , "" , "" , false )
533- v .tagCache .Set (tag , ctag )
534- }
535- v .tagCache .lock .Unlock ()
536- }
537-
523+ ctag := v .fetchCacheTag (tag )
538524 val := reflect .ValueOf (field )
539-
540525 vd := v .pool .Get ().(* validate )
541526 vd .top = val
542527 vd .isPartial = false
@@ -546,9 +531,7 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e
546531 err = vd .errs
547532 vd .errs = nil
548533 }
549-
550534 v .pool .Put (vd )
551-
552535 return
553536}
554537
@@ -589,36 +572,17 @@ func (v *Validate) VarWithValueCtx(ctx context.Context, field interface{}, other
589572 if len (tag ) == 0 || tag == skipValidationTag {
590573 return nil
591574 }
592-
593- // find cached tag
594- ctag , ok := v .tagCache .Get (tag )
595- if ! ok {
596- v .tagCache .lock .Lock ()
597-
598- // could have been multiple trying to access, but once first is done this ensures tag
599- // isn't parsed again.
600- ctag , ok = v .tagCache .Get (tag )
601- if ! ok {
602- ctag , _ = v .parseFieldTagsRecursive (tag , "" , "" , false )
603- v .tagCache .Set (tag , ctag )
604- }
605- v .tagCache .lock .Unlock ()
606- }
607-
575+ ctag := v .fetchCacheTag (tag )
608576 otherVal := reflect .ValueOf (other )
609-
610577 vd := v .pool .Get ().(* validate )
611578 vd .top = otherVal
612579 vd .isPartial = false
613-
614580 vd .traverseField (ctx , otherVal , reflect .ValueOf (field ), vd .ns [0 :0 ], vd .actualNs [0 :0 ], defaultCField , ctag )
615581
616582 if len (vd .errs ) > 0 {
617583 err = vd .errs
618584 vd .errs = nil
619585 }
620-
621586 v .pool .Put (vd )
622-
623587 return
624588}
0 commit comments