From 5fedd8c08afa3f00bc4513cde0375b17bb5f738d Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Fri, 5 Aug 2016 07:15:25 -0400 Subject: [PATCH] buffer errTag + errs array. --- validator.go | 9 +++++---- validator_instance.go | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/validator.go b/validator.go index 3ef9636..4f82f69 100644 --- a/validator.go +++ b/validator.go @@ -226,7 +226,7 @@ OUTER: case typeOr: - errTag := "" + errTag := make([]byte, 0, 64) for { @@ -252,7 +252,8 @@ OUTER: } } - errTag += orSeparator + ct.tag + errTag = append(errTag, '|') + errTag = append(errTag, ct.tag...) if ct.next == nil { // if we get here, no valid 'or' value and no more tags @@ -278,8 +279,8 @@ OUTER: v.errs = append(v.errs, &fieldError{ - tag: errTag[1:], - actualTag: errTag[1:], + tag: string(errTag)[1:], + actualTag: string(errTag)[1:], ns: string(append(ns, cf.AltName...)), structNs: string(append(structNs, cf.Name...)), field: cf.AltName, diff --git a/validator_instance.go b/validator_instance.go index 1433259..54a9f77 100644 --- a/validator_instance.go +++ b/validator_instance.go @@ -89,7 +89,8 @@ func New() *Validate { v.pool = &sync.Pool{ New: func() interface{} { return &validate{ - v: v, + v: v, + errs: make(ValidationErrors, 0, 4), } }, }