💯Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
validator/cache.go

323 lines
7.4 KiB

package validator
import (
"fmt"
"reflect"
"strings"
"sync"
"sync/atomic"
)
gain another 5% on average by changing tag type from bool's to enum ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 117 116 -0.85% BenchmarkFieldFailure-4 675 651 -3.56% BenchmarkFieldDiveSuccess-4 2518 2418 -3.97% BenchmarkFieldDiveFailure-4 3096 3011 -2.75% BenchmarkFieldCustomTypeSuccess-4 319 297 -6.90% BenchmarkFieldCustomTypeFailure-4 688 680 -1.16% BenchmarkFieldOrTagSuccess-4 1251 1176 -6.00% BenchmarkFieldOrTagFailure-4 1090 1073 -1.56% BenchmarkStructLevelValidationSuccess-4 558 567 +1.61% BenchmarkStructLevelValidationFailure-4 608 562 -7.57% BenchmarkStructSimpleCustomTypeSuccess-4 702 636 -9.40% BenchmarkStructSimpleCustomTypeFailure-4 1380 1295 -6.16% BenchmarkStructPartialSuccess-4 1139 1058 -7.11% BenchmarkStructPartialFailure-4 1760 1648 -6.36% BenchmarkStructExceptSuccess-4 951 917 -3.58% BenchmarkStructExceptFailure-4 1147 1085 -5.41% BenchmarkStructSimpleCrossFieldSuccess-4 873 783 -10.31% BenchmarkStructSimpleCrossFieldFailure-4 1478 1384 -6.36% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1328 1273 -4.14% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 1949 1896 -2.72% BenchmarkStructSimpleSuccess-4 559 523 -6.44% BenchmarkStructSimpleFailure-4 1334 1311 -1.72% BenchmarkStructSimpleSuccessParallel-4 148 137 -7.43% BenchmarkStructSimpleFailureParallel-4 631 591 -6.34% BenchmarkStructComplexSuccess-4 3476 3500 +0.69% BenchmarkStructComplexFailure-4 8467 8406 -0.72% BenchmarkStructComplexSuccessParallel-4 1098 1012 -7.83% BenchmarkStructComplexFailureParallel-4 3113 3121 +0.26% benchmark old allocs new allocs delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 4 4 +0.00% BenchmarkFieldDiveSuccess-4 28 28 +0.00% BenchmarkFieldDiveFailure-4 32 32 +0.00% BenchmarkFieldCustomTypeSuccess-4 2 2 +0.00% BenchmarkFieldCustomTypeFailure-4 4 4 +0.00% BenchmarkFieldOrTagSuccess-4 1 1 +0.00% BenchmarkFieldOrTagFailure-4 6 6 +0.00% BenchmarkStructLevelValidationSuccess-4 5 5 +0.00% BenchmarkStructLevelValidationFailure-4 5 5 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 3 3 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 9 9 +0.00% BenchmarkStructPartialSuccess-4 9 9 +0.00% BenchmarkStructPartialFailure-4 14 14 +0.00% BenchmarkStructExceptSuccess-4 7 7 +0.00% BenchmarkStructExceptFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 4 4 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 7 7 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 12 12 +0.00% BenchmarkStructSimpleSuccess-4 1 1 +0.00% BenchmarkStructSimpleFailure-4 9 9 +0.00% BenchmarkStructSimpleSuccessParallel-4 1 1 +0.00% BenchmarkStructSimpleFailureParallel-4 9 9 +0.00% BenchmarkStructComplexSuccess-4 15 15 +0.00% BenchmarkStructComplexFailure-4 60 60 +0.00% BenchmarkStructComplexSuccessParallel-4 15 15 +0.00% BenchmarkStructComplexFailureParallel-4 60 60 +0.00% benchmark old bytes new bytes delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 432 432 +0.00% BenchmarkFieldDiveSuccess-4 464 464 +0.00% BenchmarkFieldDiveFailure-4 896 896 +0.00% BenchmarkFieldCustomTypeSuccess-4 32 32 +0.00% BenchmarkFieldCustomTypeFailure-4 432 432 +0.00% BenchmarkFieldOrTagSuccess-4 4 4 +0.00% BenchmarkFieldOrTagFailure-4 448 448 +0.00% BenchmarkStructLevelValidationSuccess-4 160 160 +0.00% BenchmarkStructLevelValidationFailure-4 160 160 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 36 36 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 640 640 +0.00% BenchmarkStructPartialSuccess-4 336 336 +0.00% BenchmarkStructPartialFailure-4 794 794 +0.00% BenchmarkStructExceptSuccess-4 314 314 +0.00% BenchmarkStructExceptFailure-4 336 336 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 80 80 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 536 536 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 112 112 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 576 576 +0.00% BenchmarkStructSimpleSuccess-4 4 4 +0.00% BenchmarkStructSimpleFailure-4 640 640 +0.00% BenchmarkStructSimpleSuccessParallel-4 4 4 +0.00% BenchmarkStructSimpleFailureParallel-4 640 640 +0.00% BenchmarkStructComplexSuccess-4 244 244 +0.00% BenchmarkStructComplexFailure-4 3608 3608 +0.00% BenchmarkStructComplexSuccessParallel-4 244 244 +0.00% BenchmarkStructComplexFailureParallel-4 3608 3608 +0.00% ```
8 years ago
type tagType uint8
const (
typeDefault tagType = iota
typeOmitEmpty
typeIsDefault
gain another 5% on average by changing tag type from bool's to enum ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 117 116 -0.85% BenchmarkFieldFailure-4 675 651 -3.56% BenchmarkFieldDiveSuccess-4 2518 2418 -3.97% BenchmarkFieldDiveFailure-4 3096 3011 -2.75% BenchmarkFieldCustomTypeSuccess-4 319 297 -6.90% BenchmarkFieldCustomTypeFailure-4 688 680 -1.16% BenchmarkFieldOrTagSuccess-4 1251 1176 -6.00% BenchmarkFieldOrTagFailure-4 1090 1073 -1.56% BenchmarkStructLevelValidationSuccess-4 558 567 +1.61% BenchmarkStructLevelValidationFailure-4 608 562 -7.57% BenchmarkStructSimpleCustomTypeSuccess-4 702 636 -9.40% BenchmarkStructSimpleCustomTypeFailure-4 1380 1295 -6.16% BenchmarkStructPartialSuccess-4 1139 1058 -7.11% BenchmarkStructPartialFailure-4 1760 1648 -6.36% BenchmarkStructExceptSuccess-4 951 917 -3.58% BenchmarkStructExceptFailure-4 1147 1085 -5.41% BenchmarkStructSimpleCrossFieldSuccess-4 873 783 -10.31% BenchmarkStructSimpleCrossFieldFailure-4 1478 1384 -6.36% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1328 1273 -4.14% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 1949 1896 -2.72% BenchmarkStructSimpleSuccess-4 559 523 -6.44% BenchmarkStructSimpleFailure-4 1334 1311 -1.72% BenchmarkStructSimpleSuccessParallel-4 148 137 -7.43% BenchmarkStructSimpleFailureParallel-4 631 591 -6.34% BenchmarkStructComplexSuccess-4 3476 3500 +0.69% BenchmarkStructComplexFailure-4 8467 8406 -0.72% BenchmarkStructComplexSuccessParallel-4 1098 1012 -7.83% BenchmarkStructComplexFailureParallel-4 3113 3121 +0.26% benchmark old allocs new allocs delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 4 4 +0.00% BenchmarkFieldDiveSuccess-4 28 28 +0.00% BenchmarkFieldDiveFailure-4 32 32 +0.00% BenchmarkFieldCustomTypeSuccess-4 2 2 +0.00% BenchmarkFieldCustomTypeFailure-4 4 4 +0.00% BenchmarkFieldOrTagSuccess-4 1 1 +0.00% BenchmarkFieldOrTagFailure-4 6 6 +0.00% BenchmarkStructLevelValidationSuccess-4 5 5 +0.00% BenchmarkStructLevelValidationFailure-4 5 5 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 3 3 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 9 9 +0.00% BenchmarkStructPartialSuccess-4 9 9 +0.00% BenchmarkStructPartialFailure-4 14 14 +0.00% BenchmarkStructExceptSuccess-4 7 7 +0.00% BenchmarkStructExceptFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 4 4 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 7 7 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 12 12 +0.00% BenchmarkStructSimpleSuccess-4 1 1 +0.00% BenchmarkStructSimpleFailure-4 9 9 +0.00% BenchmarkStructSimpleSuccessParallel-4 1 1 +0.00% BenchmarkStructSimpleFailureParallel-4 9 9 +0.00% BenchmarkStructComplexSuccess-4 15 15 +0.00% BenchmarkStructComplexFailure-4 60 60 +0.00% BenchmarkStructComplexSuccessParallel-4 15 15 +0.00% BenchmarkStructComplexFailureParallel-4 60 60 +0.00% benchmark old bytes new bytes delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 432 432 +0.00% BenchmarkFieldDiveSuccess-4 464 464 +0.00% BenchmarkFieldDiveFailure-4 896 896 +0.00% BenchmarkFieldCustomTypeSuccess-4 32 32 +0.00% BenchmarkFieldCustomTypeFailure-4 432 432 +0.00% BenchmarkFieldOrTagSuccess-4 4 4 +0.00% BenchmarkFieldOrTagFailure-4 448 448 +0.00% BenchmarkStructLevelValidationSuccess-4 160 160 +0.00% BenchmarkStructLevelValidationFailure-4 160 160 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 36 36 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 640 640 +0.00% BenchmarkStructPartialSuccess-4 336 336 +0.00% BenchmarkStructPartialFailure-4 794 794 +0.00% BenchmarkStructExceptSuccess-4 314 314 +0.00% BenchmarkStructExceptFailure-4 336 336 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 80 80 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 536 536 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 112 112 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 576 576 +0.00% BenchmarkStructSimpleSuccess-4 4 4 +0.00% BenchmarkStructSimpleFailure-4 640 640 +0.00% BenchmarkStructSimpleSuccessParallel-4 4 4 +0.00% BenchmarkStructSimpleFailureParallel-4 640 640 +0.00% BenchmarkStructComplexSuccess-4 244 244 +0.00% BenchmarkStructComplexFailure-4 3608 3608 +0.00% BenchmarkStructComplexSuccessParallel-4 244 244 +0.00% BenchmarkStructComplexFailureParallel-4 3608 3608 +0.00% ```
8 years ago
typeNoStructLevel
typeStructOnly
typeDive
typeOr
typeKeys
typeEndKeys
gain another 5% on average by changing tag type from bool's to enum ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 117 116 -0.85% BenchmarkFieldFailure-4 675 651 -3.56% BenchmarkFieldDiveSuccess-4 2518 2418 -3.97% BenchmarkFieldDiveFailure-4 3096 3011 -2.75% BenchmarkFieldCustomTypeSuccess-4 319 297 -6.90% BenchmarkFieldCustomTypeFailure-4 688 680 -1.16% BenchmarkFieldOrTagSuccess-4 1251 1176 -6.00% BenchmarkFieldOrTagFailure-4 1090 1073 -1.56% BenchmarkStructLevelValidationSuccess-4 558 567 +1.61% BenchmarkStructLevelValidationFailure-4 608 562 -7.57% BenchmarkStructSimpleCustomTypeSuccess-4 702 636 -9.40% BenchmarkStructSimpleCustomTypeFailure-4 1380 1295 -6.16% BenchmarkStructPartialSuccess-4 1139 1058 -7.11% BenchmarkStructPartialFailure-4 1760 1648 -6.36% BenchmarkStructExceptSuccess-4 951 917 -3.58% BenchmarkStructExceptFailure-4 1147 1085 -5.41% BenchmarkStructSimpleCrossFieldSuccess-4 873 783 -10.31% BenchmarkStructSimpleCrossFieldFailure-4 1478 1384 -6.36% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1328 1273 -4.14% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 1949 1896 -2.72% BenchmarkStructSimpleSuccess-4 559 523 -6.44% BenchmarkStructSimpleFailure-4 1334 1311 -1.72% BenchmarkStructSimpleSuccessParallel-4 148 137 -7.43% BenchmarkStructSimpleFailureParallel-4 631 591 -6.34% BenchmarkStructComplexSuccess-4 3476 3500 +0.69% BenchmarkStructComplexFailure-4 8467 8406 -0.72% BenchmarkStructComplexSuccessParallel-4 1098 1012 -7.83% BenchmarkStructComplexFailureParallel-4 3113 3121 +0.26% benchmark old allocs new allocs delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 4 4 +0.00% BenchmarkFieldDiveSuccess-4 28 28 +0.00% BenchmarkFieldDiveFailure-4 32 32 +0.00% BenchmarkFieldCustomTypeSuccess-4 2 2 +0.00% BenchmarkFieldCustomTypeFailure-4 4 4 +0.00% BenchmarkFieldOrTagSuccess-4 1 1 +0.00% BenchmarkFieldOrTagFailure-4 6 6 +0.00% BenchmarkStructLevelValidationSuccess-4 5 5 +0.00% BenchmarkStructLevelValidationFailure-4 5 5 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 3 3 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 9 9 +0.00% BenchmarkStructPartialSuccess-4 9 9 +0.00% BenchmarkStructPartialFailure-4 14 14 +0.00% BenchmarkStructExceptSuccess-4 7 7 +0.00% BenchmarkStructExceptFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 4 4 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 7 7 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 12 12 +0.00% BenchmarkStructSimpleSuccess-4 1 1 +0.00% BenchmarkStructSimpleFailure-4 9 9 +0.00% BenchmarkStructSimpleSuccessParallel-4 1 1 +0.00% BenchmarkStructSimpleFailureParallel-4 9 9 +0.00% BenchmarkStructComplexSuccess-4 15 15 +0.00% BenchmarkStructComplexFailure-4 60 60 +0.00% BenchmarkStructComplexSuccessParallel-4 15 15 +0.00% BenchmarkStructComplexFailureParallel-4 60 60 +0.00% benchmark old bytes new bytes delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 432 432 +0.00% BenchmarkFieldDiveSuccess-4 464 464 +0.00% BenchmarkFieldDiveFailure-4 896 896 +0.00% BenchmarkFieldCustomTypeSuccess-4 32 32 +0.00% BenchmarkFieldCustomTypeFailure-4 432 432 +0.00% BenchmarkFieldOrTagSuccess-4 4 4 +0.00% BenchmarkFieldOrTagFailure-4 448 448 +0.00% BenchmarkStructLevelValidationSuccess-4 160 160 +0.00% BenchmarkStructLevelValidationFailure-4 160 160 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 36 36 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 640 640 +0.00% BenchmarkStructPartialSuccess-4 336 336 +0.00% BenchmarkStructPartialFailure-4 794 794 +0.00% BenchmarkStructExceptSuccess-4 314 314 +0.00% BenchmarkStructExceptFailure-4 336 336 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 80 80 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 536 536 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 112 112 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 576 576 +0.00% BenchmarkStructSimpleSuccess-4 4 4 +0.00% BenchmarkStructSimpleFailure-4 640 640 +0.00% BenchmarkStructSimpleSuccessParallel-4 4 4 +0.00% BenchmarkStructSimpleFailureParallel-4 640 640 +0.00% BenchmarkStructComplexSuccess-4 244 244 +0.00% BenchmarkStructComplexFailure-4 3608 3608 +0.00% BenchmarkStructComplexSuccessParallel-4 244 244 +0.00% BenchmarkStructComplexFailureParallel-4 3608 3608 +0.00% ```
8 years ago
)
8 years ago
const (
invalidValidation = "Invalid validation tag on field '%s'"
undefinedValidation = "Undefined validation function '%s' on field '%s'"
keysTagNotDefined = "'" + endKeysTag + "' tag encountered without a corresponding '" + keysTag + "' tag"
8 years ago
)
type structCache struct {
lock sync.Mutex
m atomic.Value // map[reflect.Type]*cStruct
}
func (sc *structCache) Get(key reflect.Type) (c *cStruct, found bool) {
c, found = sc.m.Load().(map[reflect.Type]*cStruct)[key]
return
}
func (sc *structCache) Set(key reflect.Type, value *cStruct) {
m := sc.m.Load().(map[reflect.Type]*cStruct)
nm := make(map[reflect.Type]*cStruct, len(m)+1)
for k, v := range m {
nm[k] = v
}
nm[key] = value
sc.m.Store(nm)
}
type tagCache struct {
lock sync.Mutex
m atomic.Value // map[string]*cTag
}
func (tc *tagCache) Get(key string) (c *cTag, found bool) {
c, found = tc.m.Load().(map[string]*cTag)[key]
return
}
func (tc *tagCache) Set(key string, value *cTag) {
m := tc.m.Load().(map[string]*cTag)
nm := make(map[string]*cTag, len(m)+1)
for k, v := range m {
nm[k] = v
}
nm[key] = value
tc.m.Store(nm)
}
type cStruct struct {
name string
change field cache to array - errors now come out in order for unit tests - speed improvement using array vs map benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-8 101 100 -0.99% BenchmarkFieldSuccessParallel-8 33.2 33.7 +1.51% BenchmarkFieldFailure-8 323 332 +2.79% BenchmarkFieldFailureParallel-8 112 113 +0.89% BenchmarkFieldDiveSuccess-8 719 714 -0.70% BenchmarkFieldDiveSuccessParallel-8 230 225 -2.17% BenchmarkFieldDiveFailure-8 1001 987 -1.40% BenchmarkFieldDiveFailureParallel-8 323 317 -1.86% BenchmarkFieldCustomTypeSuccess-8 263 264 +0.38% BenchmarkFieldCustomTypeSuccessParallel-8 82.6 81.4 -1.45% BenchmarkFieldCustomTypeFailure-8 327 328 +0.31% BenchmarkFieldCustomTypeFailureParallel-8 116 116 +0.00% BenchmarkFieldOrTagSuccess-8 871 878 +0.80% BenchmarkFieldOrTagSuccessParallel-8 394 402 +2.03% BenchmarkFieldOrTagFailure-8 568 569 +0.18% BenchmarkFieldOrTagFailureParallel-8 397 401 +1.01% BenchmarkStructLevelValidationSuccess-8 332 267 -19.58% BenchmarkStructLevelValidationSuccessParallel-8 105 82.4 -21.52% BenchmarkStructLevelValidationFailure-8 637 557 -12.56% BenchmarkStructLevelValidationFailureParallel-8 260 226 -13.08% BenchmarkStructSimpleCustomTypeSuccess-8 525 452 -13.90% BenchmarkStructSimpleCustomTypeSuccessParallel-8 155 144 -7.10% BenchmarkStructSimpleCustomTypeFailure-8 828 738 -10.87% BenchmarkStructSimpleCustomTypeFailureParallel-8 345 285 -17.39% BenchmarkStructFilteredSuccess-8 744 664 -10.75% BenchmarkStructFilteredSuccessParallel-8 274 257 -6.20% BenchmarkStructFilteredFailure-8 595 517 -13.11% BenchmarkStructFilteredFailureParallel-8 250 195 -22.00% BenchmarkStructPartialSuccess-8 674 608 -9.79% BenchmarkStructPartialSuccessParallel-8 256 225 -12.11% BenchmarkStructPartialFailure-8 928 848 -8.62% BenchmarkStructPartialFailureParallel-8 399 360 -9.77% BenchmarkStructExceptSuccess-8 1076 934 -13.20% BenchmarkStructExceptSuccessParallel-8 237 200 -15.61% BenchmarkStructExceptFailure-8 873 787 -9.85% BenchmarkStructExceptFailureParallel-8 365 333 -8.77% BenchmarkStructSimpleCrossFieldSuccess-8 539 489 -9.28% BenchmarkStructSimpleCrossFieldSuccessParallel-8 201 168 -16.42% BenchmarkStructSimpleCrossFieldFailure-8 788 709 -10.03% BenchmarkStructSimpleCrossFieldFailureParallel-8 322 299 -7.14% BenchmarkStructSimpleCrossStructCrossFieldSuccess-8 795 683 -14.09% BenchmarkStructSimpleCrossStructCrossFieldSuccessParallel-8 241 211 -12.45% BenchmarkStructSimpleCrossStructCrossFieldFailure-8 1110 940 -15.32% BenchmarkStructSimpleCrossStructCrossFieldFailureParallel-8 399 333 -16.54% BenchmarkStructSimpleSuccess-8 367 285 -22.34% BenchmarkStructSimpleSuccessParallel-8 108 91.0 -15.74% BenchmarkStructSimpleFailure-8 776 698 -10.05% BenchmarkStructSimpleFailureParallel-8 307 284 -7.49% BenchmarkStructComplexSuccess-8 2224 1622 -27.07% BenchmarkStructComplexSuccessParallel-8 718 526 -26.74% BenchmarkStructComplexFailure-8 5350 4717 -11.83% BenchmarkStructComplexFailureParallel-8 2097 1853 -11.64%
8 years ago
fields []*cField
fn StructLevelFuncCtx
}
type cField struct {
idx int
name string
altName string
namesEqual bool
cTags *cTag
}
type cTag struct {
tag string
aliasTag string
actualAliasTag string
param string
keys *cTag // only populated when using tag's 'keys' and 'endkeys' for map key validation
next *cTag
fn FuncCtx
typeof tagType
hasTag bool
hasAlias bool
hasParam bool // true if parameter used eg. eq= where the equal sign has been set
isBlockEnd bool // indicates the current tag represents the last validation in the block
runValidationWhenNil bool
}
func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStruct {
v.structCache.lock.Lock()
code cleanup + add missing tag cache with FieldWith func Still looking good: ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 167 119 -28.74% BenchmarkFieldFailure-4 701 650 -7.28% BenchmarkFieldDiveSuccess-4 2937 2482 -15.49% BenchmarkFieldDiveFailure-4 3536 3046 -13.86% BenchmarkFieldCustomTypeSuccess-4 341 296 -13.20% BenchmarkFieldCustomTypeFailure-4 679 666 -1.91% BenchmarkFieldOrTagSuccess-4 1157 1124 -2.85% BenchmarkFieldOrTagFailure-4 1109 1036 -6.58% BenchmarkStructLevelValidationSuccess-4 694 554 -20.17% BenchmarkStructLevelValidationFailure-4 1311 558 -57.44% BenchmarkStructSimpleCustomTypeSuccess-4 894 654 -26.85% BenchmarkStructSimpleCustomTypeFailure-4 1496 1286 -14.04% BenchmarkStructPartialSuccess-4 1229 1062 -13.59% BenchmarkStructPartialFailure-4 1838 1639 -10.83% BenchmarkStructExceptSuccess-4 961 919 -4.37% BenchmarkStructExceptFailure-4 1218 1072 -11.99% BenchmarkStructSimpleCrossFieldSuccess-4 954 800 -16.14% BenchmarkStructSimpleCrossFieldFailure-4 1569 1372 -12.56% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1588 1274 -19.77% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 2217 1901 -14.25% BenchmarkStructSimpleSuccess-4 925 512 -44.65% BenchmarkStructSimpleFailure-4 1650 1318 -20.12% BenchmarkStructSimpleSuccessParallel-4 261 144 -44.83% BenchmarkStructSimpleFailureParallel-4 758 581 -23.35% BenchmarkStructComplexSuccess-4 5868 3451 -41.19% BenchmarkStructComplexFailure-4 10767 8351 -22.44% BenchmarkStructComplexSuccessParallel-4 1559 1065 -31.69% BenchmarkStructComplexFailureParallel-4 3747 2916 -22.18% ```
8 years ago
defer v.structCache.lock.Unlock() // leave as defer! because if inner panics, it will never get unlocked otherwise!
typ := current.Type()
// could have been multiple trying to access, but once first is done this ensures struct
// isn't parsed again.
cs, ok := v.structCache.Get(typ)
if ok {
return cs
}
change field cache to array - errors now come out in order for unit tests - speed improvement using array vs map benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-8 101 100 -0.99% BenchmarkFieldSuccessParallel-8 33.2 33.7 +1.51% BenchmarkFieldFailure-8 323 332 +2.79% BenchmarkFieldFailureParallel-8 112 113 +0.89% BenchmarkFieldDiveSuccess-8 719 714 -0.70% BenchmarkFieldDiveSuccessParallel-8 230 225 -2.17% BenchmarkFieldDiveFailure-8 1001 987 -1.40% BenchmarkFieldDiveFailureParallel-8 323 317 -1.86% BenchmarkFieldCustomTypeSuccess-8 263 264 +0.38% BenchmarkFieldCustomTypeSuccessParallel-8 82.6 81.4 -1.45% BenchmarkFieldCustomTypeFailure-8 327 328 +0.31% BenchmarkFieldCustomTypeFailureParallel-8 116 116 +0.00% BenchmarkFieldOrTagSuccess-8 871 878 +0.80% BenchmarkFieldOrTagSuccessParallel-8 394 402 +2.03% BenchmarkFieldOrTagFailure-8 568 569 +0.18% BenchmarkFieldOrTagFailureParallel-8 397 401 +1.01% BenchmarkStructLevelValidationSuccess-8 332 267 -19.58% BenchmarkStructLevelValidationSuccessParallel-8 105 82.4 -21.52% BenchmarkStructLevelValidationFailure-8 637 557 -12.56% BenchmarkStructLevelValidationFailureParallel-8 260 226 -13.08% BenchmarkStructSimpleCustomTypeSuccess-8 525 452 -13.90% BenchmarkStructSimpleCustomTypeSuccessParallel-8 155 144 -7.10% BenchmarkStructSimpleCustomTypeFailure-8 828 738 -10.87% BenchmarkStructSimpleCustomTypeFailureParallel-8 345 285 -17.39% BenchmarkStructFilteredSuccess-8 744 664 -10.75% BenchmarkStructFilteredSuccessParallel-8 274 257 -6.20% BenchmarkStructFilteredFailure-8 595 517 -13.11% BenchmarkStructFilteredFailureParallel-8 250 195 -22.00% BenchmarkStructPartialSuccess-8 674 608 -9.79% BenchmarkStructPartialSuccessParallel-8 256 225 -12.11% BenchmarkStructPartialFailure-8 928 848 -8.62% BenchmarkStructPartialFailureParallel-8 399 360 -9.77% BenchmarkStructExceptSuccess-8 1076 934 -13.20% BenchmarkStructExceptSuccessParallel-8 237 200 -15.61% BenchmarkStructExceptFailure-8 873 787 -9.85% BenchmarkStructExceptFailureParallel-8 365 333 -8.77% BenchmarkStructSimpleCrossFieldSuccess-8 539 489 -9.28% BenchmarkStructSimpleCrossFieldSuccessParallel-8 201 168 -16.42% BenchmarkStructSimpleCrossFieldFailure-8 788 709 -10.03% BenchmarkStructSimpleCrossFieldFailureParallel-8 322 299 -7.14% BenchmarkStructSimpleCrossStructCrossFieldSuccess-8 795 683 -14.09% BenchmarkStructSimpleCrossStructCrossFieldSuccessParallel-8 241 211 -12.45% BenchmarkStructSimpleCrossStructCrossFieldFailure-8 1110 940 -15.32% BenchmarkStructSimpleCrossStructCrossFieldFailureParallel-8 399 333 -16.54% BenchmarkStructSimpleSuccess-8 367 285 -22.34% BenchmarkStructSimpleSuccessParallel-8 108 91.0 -15.74% BenchmarkStructSimpleFailure-8 776 698 -10.05% BenchmarkStructSimpleFailureParallel-8 307 284 -7.49% BenchmarkStructComplexSuccess-8 2224 1622 -27.07% BenchmarkStructComplexSuccessParallel-8 718 526 -26.74% BenchmarkStructComplexFailure-8 5350 4717 -11.83% BenchmarkStructComplexFailureParallel-8 2097 1853 -11.64%
8 years ago
cs = &cStruct{name: sName, fields: make([]*cField, 0), fn: v.structLevelFuncs[typ]}
numFields := current.NumField()
var ctag *cTag
var fld reflect.StructField
var tag string
var customName string
for i := 0; i < numFields; i++ {
fld = typ.Field(i)
8 years ago
if !fld.Anonymous && len(fld.PkgPath) > 0 {
continue
}
tag = fld.Tag.Get(v.tagName)
if tag == skipValidationTag {
continue
}
customName = fld.Name
8 years ago
if v.hasTagNameFunc {
name := v.tagNameFunc(fld)
if len(name) > 0 {
customName = name
}
}
code cleanup + add missing tag cache with FieldWith func Still looking good: ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 167 119 -28.74% BenchmarkFieldFailure-4 701 650 -7.28% BenchmarkFieldDiveSuccess-4 2937 2482 -15.49% BenchmarkFieldDiveFailure-4 3536 3046 -13.86% BenchmarkFieldCustomTypeSuccess-4 341 296 -13.20% BenchmarkFieldCustomTypeFailure-4 679 666 -1.91% BenchmarkFieldOrTagSuccess-4 1157 1124 -2.85% BenchmarkFieldOrTagFailure-4 1109 1036 -6.58% BenchmarkStructLevelValidationSuccess-4 694 554 -20.17% BenchmarkStructLevelValidationFailure-4 1311 558 -57.44% BenchmarkStructSimpleCustomTypeSuccess-4 894 654 -26.85% BenchmarkStructSimpleCustomTypeFailure-4 1496 1286 -14.04% BenchmarkStructPartialSuccess-4 1229 1062 -13.59% BenchmarkStructPartialFailure-4 1838 1639 -10.83% BenchmarkStructExceptSuccess-4 961 919 -4.37% BenchmarkStructExceptFailure-4 1218 1072 -11.99% BenchmarkStructSimpleCrossFieldSuccess-4 954 800 -16.14% BenchmarkStructSimpleCrossFieldFailure-4 1569 1372 -12.56% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1588 1274 -19.77% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 2217 1901 -14.25% BenchmarkStructSimpleSuccess-4 925 512 -44.65% BenchmarkStructSimpleFailure-4 1650 1318 -20.12% BenchmarkStructSimpleSuccessParallel-4 261 144 -44.83% BenchmarkStructSimpleFailureParallel-4 758 581 -23.35% BenchmarkStructComplexSuccess-4 5868 3451 -41.19% BenchmarkStructComplexFailure-4 10767 8351 -22.44% BenchmarkStructComplexSuccessParallel-4 1559 1065 -31.69% BenchmarkStructComplexFailureParallel-4 3747 2916 -22.18% ```
8 years ago
// NOTE: cannot use shared tag cache, because tags may be equal, but things like alias may be different
// and so only struct level caching can be used instead of combined with Field tag caching
if len(tag) > 0 {
8 years ago
ctag, _ = v.parseFieldTagsRecursive(tag, fld.Name, "", false)
} else {
// even if field doesn't have validations need cTag for traversing to potential inner/nested
// elements of the field.
ctag = new(cTag)
}
change field cache to array - errors now come out in order for unit tests - speed improvement using array vs map benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-8 101 100 -0.99% BenchmarkFieldSuccessParallel-8 33.2 33.7 +1.51% BenchmarkFieldFailure-8 323 332 +2.79% BenchmarkFieldFailureParallel-8 112 113 +0.89% BenchmarkFieldDiveSuccess-8 719 714 -0.70% BenchmarkFieldDiveSuccessParallel-8 230 225 -2.17% BenchmarkFieldDiveFailure-8 1001 987 -1.40% BenchmarkFieldDiveFailureParallel-8 323 317 -1.86% BenchmarkFieldCustomTypeSuccess-8 263 264 +0.38% BenchmarkFieldCustomTypeSuccessParallel-8 82.6 81.4 -1.45% BenchmarkFieldCustomTypeFailure-8 327 328 +0.31% BenchmarkFieldCustomTypeFailureParallel-8 116 116 +0.00% BenchmarkFieldOrTagSuccess-8 871 878 +0.80% BenchmarkFieldOrTagSuccessParallel-8 394 402 +2.03% BenchmarkFieldOrTagFailure-8 568 569 +0.18% BenchmarkFieldOrTagFailureParallel-8 397 401 +1.01% BenchmarkStructLevelValidationSuccess-8 332 267 -19.58% BenchmarkStructLevelValidationSuccessParallel-8 105 82.4 -21.52% BenchmarkStructLevelValidationFailure-8 637 557 -12.56% BenchmarkStructLevelValidationFailureParallel-8 260 226 -13.08% BenchmarkStructSimpleCustomTypeSuccess-8 525 452 -13.90% BenchmarkStructSimpleCustomTypeSuccessParallel-8 155 144 -7.10% BenchmarkStructSimpleCustomTypeFailure-8 828 738 -10.87% BenchmarkStructSimpleCustomTypeFailureParallel-8 345 285 -17.39% BenchmarkStructFilteredSuccess-8 744 664 -10.75% BenchmarkStructFilteredSuccessParallel-8 274 257 -6.20% BenchmarkStructFilteredFailure-8 595 517 -13.11% BenchmarkStructFilteredFailureParallel-8 250 195 -22.00% BenchmarkStructPartialSuccess-8 674 608 -9.79% BenchmarkStructPartialSuccessParallel-8 256 225 -12.11% BenchmarkStructPartialFailure-8 928 848 -8.62% BenchmarkStructPartialFailureParallel-8 399 360 -9.77% BenchmarkStructExceptSuccess-8 1076 934 -13.20% BenchmarkStructExceptSuccessParallel-8 237 200 -15.61% BenchmarkStructExceptFailure-8 873 787 -9.85% BenchmarkStructExceptFailureParallel-8 365 333 -8.77% BenchmarkStructSimpleCrossFieldSuccess-8 539 489 -9.28% BenchmarkStructSimpleCrossFieldSuccessParallel-8 201 168 -16.42% BenchmarkStructSimpleCrossFieldFailure-8 788 709 -10.03% BenchmarkStructSimpleCrossFieldFailureParallel-8 322 299 -7.14% BenchmarkStructSimpleCrossStructCrossFieldSuccess-8 795 683 -14.09% BenchmarkStructSimpleCrossStructCrossFieldSuccessParallel-8 241 211 -12.45% BenchmarkStructSimpleCrossStructCrossFieldFailure-8 1110 940 -15.32% BenchmarkStructSimpleCrossStructCrossFieldFailureParallel-8 399 333 -16.54% BenchmarkStructSimpleSuccess-8 367 285 -22.34% BenchmarkStructSimpleSuccessParallel-8 108 91.0 -15.74% BenchmarkStructSimpleFailure-8 776 698 -10.05% BenchmarkStructSimpleFailureParallel-8 307 284 -7.49% BenchmarkStructComplexSuccess-8 2224 1622 -27.07% BenchmarkStructComplexSuccessParallel-8 718 526 -26.74% BenchmarkStructComplexFailure-8 5350 4717 -11.83% BenchmarkStructComplexFailureParallel-8 2097 1853 -11.64%
8 years ago
cs.fields = append(cs.fields, &cField{
idx: i,
name: fld.Name,
altName: customName,
cTags: ctag,
namesEqual: fld.Name == customName,
change field cache to array - errors now come out in order for unit tests - speed improvement using array vs map benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-8 101 100 -0.99% BenchmarkFieldSuccessParallel-8 33.2 33.7 +1.51% BenchmarkFieldFailure-8 323 332 +2.79% BenchmarkFieldFailureParallel-8 112 113 +0.89% BenchmarkFieldDiveSuccess-8 719 714 -0.70% BenchmarkFieldDiveSuccessParallel-8 230 225 -2.17% BenchmarkFieldDiveFailure-8 1001 987 -1.40% BenchmarkFieldDiveFailureParallel-8 323 317 -1.86% BenchmarkFieldCustomTypeSuccess-8 263 264 +0.38% BenchmarkFieldCustomTypeSuccessParallel-8 82.6 81.4 -1.45% BenchmarkFieldCustomTypeFailure-8 327 328 +0.31% BenchmarkFieldCustomTypeFailureParallel-8 116 116 +0.00% BenchmarkFieldOrTagSuccess-8 871 878 +0.80% BenchmarkFieldOrTagSuccessParallel-8 394 402 +2.03% BenchmarkFieldOrTagFailure-8 568 569 +0.18% BenchmarkFieldOrTagFailureParallel-8 397 401 +1.01% BenchmarkStructLevelValidationSuccess-8 332 267 -19.58% BenchmarkStructLevelValidationSuccessParallel-8 105 82.4 -21.52% BenchmarkStructLevelValidationFailure-8 637 557 -12.56% BenchmarkStructLevelValidationFailureParallel-8 260 226 -13.08% BenchmarkStructSimpleCustomTypeSuccess-8 525 452 -13.90% BenchmarkStructSimpleCustomTypeSuccessParallel-8 155 144 -7.10% BenchmarkStructSimpleCustomTypeFailure-8 828 738 -10.87% BenchmarkStructSimpleCustomTypeFailureParallel-8 345 285 -17.39% BenchmarkStructFilteredSuccess-8 744 664 -10.75% BenchmarkStructFilteredSuccessParallel-8 274 257 -6.20% BenchmarkStructFilteredFailure-8 595 517 -13.11% BenchmarkStructFilteredFailureParallel-8 250 195 -22.00% BenchmarkStructPartialSuccess-8 674 608 -9.79% BenchmarkStructPartialSuccessParallel-8 256 225 -12.11% BenchmarkStructPartialFailure-8 928 848 -8.62% BenchmarkStructPartialFailureParallel-8 399 360 -9.77% BenchmarkStructExceptSuccess-8 1076 934 -13.20% BenchmarkStructExceptSuccessParallel-8 237 200 -15.61% BenchmarkStructExceptFailure-8 873 787 -9.85% BenchmarkStructExceptFailureParallel-8 365 333 -8.77% BenchmarkStructSimpleCrossFieldSuccess-8 539 489 -9.28% BenchmarkStructSimpleCrossFieldSuccessParallel-8 201 168 -16.42% BenchmarkStructSimpleCrossFieldFailure-8 788 709 -10.03% BenchmarkStructSimpleCrossFieldFailureParallel-8 322 299 -7.14% BenchmarkStructSimpleCrossStructCrossFieldSuccess-8 795 683 -14.09% BenchmarkStructSimpleCrossStructCrossFieldSuccessParallel-8 241 211 -12.45% BenchmarkStructSimpleCrossStructCrossFieldFailure-8 1110 940 -15.32% BenchmarkStructSimpleCrossStructCrossFieldFailureParallel-8 399 333 -16.54% BenchmarkStructSimpleSuccess-8 367 285 -22.34% BenchmarkStructSimpleSuccessParallel-8 108 91.0 -15.74% BenchmarkStructSimpleFailure-8 776 698 -10.05% BenchmarkStructSimpleFailureParallel-8 307 284 -7.49% BenchmarkStructComplexSuccess-8 2224 1622 -27.07% BenchmarkStructComplexSuccessParallel-8 718 526 -26.74% BenchmarkStructComplexFailure-8 5350 4717 -11.83% BenchmarkStructComplexFailureParallel-8 2097 1853 -11.64%
8 years ago
})
}
v.structCache.Set(typ, cs)
return cs
}
func (v *Validate) parseFieldTagsRecursive(tag string, fieldName string, alias string, hasAlias bool) (firstCtag *cTag, current *cTag) {
var t string
noAlias := len(alias) == 0
tags := strings.Split(tag, tagSeparator)
for i := 0; i < len(tags); i++ {
t = tags[i]
if noAlias {
alias = t
}
8 years ago
// check map for alias and process new tags, otherwise process as usual
if tagsVal, found := v.aliases[t]; found {
if i == 0 {
firstCtag, current = v.parseFieldTagsRecursive(tagsVal, fieldName, t, true)
} else {
next, curr := v.parseFieldTagsRecursive(tagsVal, fieldName, t, true)
current.next, current = next, curr
}
8 years ago
continue
}
var prevTag tagType
if i == 0 {
5 years ago
current = &cTag{aliasTag: alias, hasAlias: hasAlias, hasTag: true, typeof: typeDefault}
firstCtag = current
} else {
prevTag = current.typeof
current.next = &cTag{aliasTag: alias, hasAlias: hasAlias, hasTag: true}
current = current.next
}
switch t {
case diveTag:
gain another 5% on average by changing tag type from bool's to enum ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 117 116 -0.85% BenchmarkFieldFailure-4 675 651 -3.56% BenchmarkFieldDiveSuccess-4 2518 2418 -3.97% BenchmarkFieldDiveFailure-4 3096 3011 -2.75% BenchmarkFieldCustomTypeSuccess-4 319 297 -6.90% BenchmarkFieldCustomTypeFailure-4 688 680 -1.16% BenchmarkFieldOrTagSuccess-4 1251 1176 -6.00% BenchmarkFieldOrTagFailure-4 1090 1073 -1.56% BenchmarkStructLevelValidationSuccess-4 558 567 +1.61% BenchmarkStructLevelValidationFailure-4 608 562 -7.57% BenchmarkStructSimpleCustomTypeSuccess-4 702 636 -9.40% BenchmarkStructSimpleCustomTypeFailure-4 1380 1295 -6.16% BenchmarkStructPartialSuccess-4 1139 1058 -7.11% BenchmarkStructPartialFailure-4 1760 1648 -6.36% BenchmarkStructExceptSuccess-4 951 917 -3.58% BenchmarkStructExceptFailure-4 1147 1085 -5.41% BenchmarkStructSimpleCrossFieldSuccess-4 873 783 -10.31% BenchmarkStructSimpleCrossFieldFailure-4 1478 1384 -6.36% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1328 1273 -4.14% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 1949 1896 -2.72% BenchmarkStructSimpleSuccess-4 559 523 -6.44% BenchmarkStructSimpleFailure-4 1334 1311 -1.72% BenchmarkStructSimpleSuccessParallel-4 148 137 -7.43% BenchmarkStructSimpleFailureParallel-4 631 591 -6.34% BenchmarkStructComplexSuccess-4 3476 3500 +0.69% BenchmarkStructComplexFailure-4 8467 8406 -0.72% BenchmarkStructComplexSuccessParallel-4 1098 1012 -7.83% BenchmarkStructComplexFailureParallel-4 3113 3121 +0.26% benchmark old allocs new allocs delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 4 4 +0.00% BenchmarkFieldDiveSuccess-4 28 28 +0.00% BenchmarkFieldDiveFailure-4 32 32 +0.00% BenchmarkFieldCustomTypeSuccess-4 2 2 +0.00% BenchmarkFieldCustomTypeFailure-4 4 4 +0.00% BenchmarkFieldOrTagSuccess-4 1 1 +0.00% BenchmarkFieldOrTagFailure-4 6 6 +0.00% BenchmarkStructLevelValidationSuccess-4 5 5 +0.00% BenchmarkStructLevelValidationFailure-4 5 5 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 3 3 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 9 9 +0.00% BenchmarkStructPartialSuccess-4 9 9 +0.00% BenchmarkStructPartialFailure-4 14 14 +0.00% BenchmarkStructExceptSuccess-4 7 7 +0.00% BenchmarkStructExceptFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 4 4 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 7 7 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 12 12 +0.00% BenchmarkStructSimpleSuccess-4 1 1 +0.00% BenchmarkStructSimpleFailure-4 9 9 +0.00% BenchmarkStructSimpleSuccessParallel-4 1 1 +0.00% BenchmarkStructSimpleFailureParallel-4 9 9 +0.00% BenchmarkStructComplexSuccess-4 15 15 +0.00% BenchmarkStructComplexFailure-4 60 60 +0.00% BenchmarkStructComplexSuccessParallel-4 15 15 +0.00% BenchmarkStructComplexFailureParallel-4 60 60 +0.00% benchmark old bytes new bytes delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 432 432 +0.00% BenchmarkFieldDiveSuccess-4 464 464 +0.00% BenchmarkFieldDiveFailure-4 896 896 +0.00% BenchmarkFieldCustomTypeSuccess-4 32 32 +0.00% BenchmarkFieldCustomTypeFailure-4 432 432 +0.00% BenchmarkFieldOrTagSuccess-4 4 4 +0.00% BenchmarkFieldOrTagFailure-4 448 448 +0.00% BenchmarkStructLevelValidationSuccess-4 160 160 +0.00% BenchmarkStructLevelValidationFailure-4 160 160 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 36 36 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 640 640 +0.00% BenchmarkStructPartialSuccess-4 336 336 +0.00% BenchmarkStructPartialFailure-4 794 794 +0.00% BenchmarkStructExceptSuccess-4 314 314 +0.00% BenchmarkStructExceptFailure-4 336 336 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 80 80 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 536 536 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 112 112 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 576 576 +0.00% BenchmarkStructSimpleSuccess-4 4 4 +0.00% BenchmarkStructSimpleFailure-4 640 640 +0.00% BenchmarkStructSimpleSuccessParallel-4 4 4 +0.00% BenchmarkStructSimpleFailureParallel-4 640 640 +0.00% BenchmarkStructComplexSuccess-4 244 244 +0.00% BenchmarkStructComplexFailure-4 3608 3608 +0.00% BenchmarkStructComplexSuccessParallel-4 244 244 +0.00% BenchmarkStructComplexFailureParallel-4 3608 3608 +0.00% ```
8 years ago
current.typeof = typeDive
continue
case keysTag:
current.typeof = typeKeys
if i == 0 || prevTag != typeDive {
panic(fmt.Sprintf("'%s' tag must be immediately preceded by the '%s' tag", keysTag, diveTag))
}
current.typeof = typeKeys
// need to pass along only keys tag
// need to increment i to skip over the keys tags
b := make([]byte, 0, 64)
i++
for ; i < len(tags); i++ {
b = append(b, tags[i]...)
b = append(b, ',')
if tags[i] == endKeysTag {
break
}
}
current.keys, _ = v.parseFieldTagsRecursive(string(b[:len(b)-1]), fieldName, "", false)
continue
case endKeysTag:
current.typeof = typeEndKeys
// if there are more in tags then there was no keysTag defined
// and an error should be thrown
if i != len(tags)-1 {
panic(keysTagNotDefined)
}
return
case omitempty:
gain another 5% on average by changing tag type from bool's to enum ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 117 116 -0.85% BenchmarkFieldFailure-4 675 651 -3.56% BenchmarkFieldDiveSuccess-4 2518 2418 -3.97% BenchmarkFieldDiveFailure-4 3096 3011 -2.75% BenchmarkFieldCustomTypeSuccess-4 319 297 -6.90% BenchmarkFieldCustomTypeFailure-4 688 680 -1.16% BenchmarkFieldOrTagSuccess-4 1251 1176 -6.00% BenchmarkFieldOrTagFailure-4 1090 1073 -1.56% BenchmarkStructLevelValidationSuccess-4 558 567 +1.61% BenchmarkStructLevelValidationFailure-4 608 562 -7.57% BenchmarkStructSimpleCustomTypeSuccess-4 702 636 -9.40% BenchmarkStructSimpleCustomTypeFailure-4 1380 1295 -6.16% BenchmarkStructPartialSuccess-4 1139 1058 -7.11% BenchmarkStructPartialFailure-4 1760 1648 -6.36% BenchmarkStructExceptSuccess-4 951 917 -3.58% BenchmarkStructExceptFailure-4 1147 1085 -5.41% BenchmarkStructSimpleCrossFieldSuccess-4 873 783 -10.31% BenchmarkStructSimpleCrossFieldFailure-4 1478 1384 -6.36% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1328 1273 -4.14% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 1949 1896 -2.72% BenchmarkStructSimpleSuccess-4 559 523 -6.44% BenchmarkStructSimpleFailure-4 1334 1311 -1.72% BenchmarkStructSimpleSuccessParallel-4 148 137 -7.43% BenchmarkStructSimpleFailureParallel-4 631 591 -6.34% BenchmarkStructComplexSuccess-4 3476 3500 +0.69% BenchmarkStructComplexFailure-4 8467 8406 -0.72% BenchmarkStructComplexSuccessParallel-4 1098 1012 -7.83% BenchmarkStructComplexFailureParallel-4 3113 3121 +0.26% benchmark old allocs new allocs delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 4 4 +0.00% BenchmarkFieldDiveSuccess-4 28 28 +0.00% BenchmarkFieldDiveFailure-4 32 32 +0.00% BenchmarkFieldCustomTypeSuccess-4 2 2 +0.00% BenchmarkFieldCustomTypeFailure-4 4 4 +0.00% BenchmarkFieldOrTagSuccess-4 1 1 +0.00% BenchmarkFieldOrTagFailure-4 6 6 +0.00% BenchmarkStructLevelValidationSuccess-4 5 5 +0.00% BenchmarkStructLevelValidationFailure-4 5 5 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 3 3 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 9 9 +0.00% BenchmarkStructPartialSuccess-4 9 9 +0.00% BenchmarkStructPartialFailure-4 14 14 +0.00% BenchmarkStructExceptSuccess-4 7 7 +0.00% BenchmarkStructExceptFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 4 4 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 7 7 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 12 12 +0.00% BenchmarkStructSimpleSuccess-4 1 1 +0.00% BenchmarkStructSimpleFailure-4 9 9 +0.00% BenchmarkStructSimpleSuccessParallel-4 1 1 +0.00% BenchmarkStructSimpleFailureParallel-4 9 9 +0.00% BenchmarkStructComplexSuccess-4 15 15 +0.00% BenchmarkStructComplexFailure-4 60 60 +0.00% BenchmarkStructComplexSuccessParallel-4 15 15 +0.00% BenchmarkStructComplexFailureParallel-4 60 60 +0.00% benchmark old bytes new bytes delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 432 432 +0.00% BenchmarkFieldDiveSuccess-4 464 464 +0.00% BenchmarkFieldDiveFailure-4 896 896 +0.00% BenchmarkFieldCustomTypeSuccess-4 32 32 +0.00% BenchmarkFieldCustomTypeFailure-4 432 432 +0.00% BenchmarkFieldOrTagSuccess-4 4 4 +0.00% BenchmarkFieldOrTagFailure-4 448 448 +0.00% BenchmarkStructLevelValidationSuccess-4 160 160 +0.00% BenchmarkStructLevelValidationFailure-4 160 160 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 36 36 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 640 640 +0.00% BenchmarkStructPartialSuccess-4 336 336 +0.00% BenchmarkStructPartialFailure-4 794 794 +0.00% BenchmarkStructExceptSuccess-4 314 314 +0.00% BenchmarkStructExceptFailure-4 336 336 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 80 80 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 536 536 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 112 112 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 576 576 +0.00% BenchmarkStructSimpleSuccess-4 4 4 +0.00% BenchmarkStructSimpleFailure-4 640 640 +0.00% BenchmarkStructSimpleSuccessParallel-4 4 4 +0.00% BenchmarkStructSimpleFailureParallel-4 640 640 +0.00% BenchmarkStructComplexSuccess-4 244 244 +0.00% BenchmarkStructComplexFailure-4 3608 3608 +0.00% BenchmarkStructComplexSuccessParallel-4 244 244 +0.00% BenchmarkStructComplexFailureParallel-4 3608 3608 +0.00% ```
8 years ago
current.typeof = typeOmitEmpty
continue
case structOnlyTag:
gain another 5% on average by changing tag type from bool's to enum ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 117 116 -0.85% BenchmarkFieldFailure-4 675 651 -3.56% BenchmarkFieldDiveSuccess-4 2518 2418 -3.97% BenchmarkFieldDiveFailure-4 3096 3011 -2.75% BenchmarkFieldCustomTypeSuccess-4 319 297 -6.90% BenchmarkFieldCustomTypeFailure-4 688 680 -1.16% BenchmarkFieldOrTagSuccess-4 1251 1176 -6.00% BenchmarkFieldOrTagFailure-4 1090 1073 -1.56% BenchmarkStructLevelValidationSuccess-4 558 567 +1.61% BenchmarkStructLevelValidationFailure-4 608 562 -7.57% BenchmarkStructSimpleCustomTypeSuccess-4 702 636 -9.40% BenchmarkStructSimpleCustomTypeFailure-4 1380 1295 -6.16% BenchmarkStructPartialSuccess-4 1139 1058 -7.11% BenchmarkStructPartialFailure-4 1760 1648 -6.36% BenchmarkStructExceptSuccess-4 951 917 -3.58% BenchmarkStructExceptFailure-4 1147 1085 -5.41% BenchmarkStructSimpleCrossFieldSuccess-4 873 783 -10.31% BenchmarkStructSimpleCrossFieldFailure-4 1478 1384 -6.36% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1328 1273 -4.14% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 1949 1896 -2.72% BenchmarkStructSimpleSuccess-4 559 523 -6.44% BenchmarkStructSimpleFailure-4 1334 1311 -1.72% BenchmarkStructSimpleSuccessParallel-4 148 137 -7.43% BenchmarkStructSimpleFailureParallel-4 631 591 -6.34% BenchmarkStructComplexSuccess-4 3476 3500 +0.69% BenchmarkStructComplexFailure-4 8467 8406 -0.72% BenchmarkStructComplexSuccessParallel-4 1098 1012 -7.83% BenchmarkStructComplexFailureParallel-4 3113 3121 +0.26% benchmark old allocs new allocs delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 4 4 +0.00% BenchmarkFieldDiveSuccess-4 28 28 +0.00% BenchmarkFieldDiveFailure-4 32 32 +0.00% BenchmarkFieldCustomTypeSuccess-4 2 2 +0.00% BenchmarkFieldCustomTypeFailure-4 4 4 +0.00% BenchmarkFieldOrTagSuccess-4 1 1 +0.00% BenchmarkFieldOrTagFailure-4 6 6 +0.00% BenchmarkStructLevelValidationSuccess-4 5 5 +0.00% BenchmarkStructLevelValidationFailure-4 5 5 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 3 3 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 9 9 +0.00% BenchmarkStructPartialSuccess-4 9 9 +0.00% BenchmarkStructPartialFailure-4 14 14 +0.00% BenchmarkStructExceptSuccess-4 7 7 +0.00% BenchmarkStructExceptFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 4 4 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 7 7 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 12 12 +0.00% BenchmarkStructSimpleSuccess-4 1 1 +0.00% BenchmarkStructSimpleFailure-4 9 9 +0.00% BenchmarkStructSimpleSuccessParallel-4 1 1 +0.00% BenchmarkStructSimpleFailureParallel-4 9 9 +0.00% BenchmarkStructComplexSuccess-4 15 15 +0.00% BenchmarkStructComplexFailure-4 60 60 +0.00% BenchmarkStructComplexSuccessParallel-4 15 15 +0.00% BenchmarkStructComplexFailureParallel-4 60 60 +0.00% benchmark old bytes new bytes delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 432 432 +0.00% BenchmarkFieldDiveSuccess-4 464 464 +0.00% BenchmarkFieldDiveFailure-4 896 896 +0.00% BenchmarkFieldCustomTypeSuccess-4 32 32 +0.00% BenchmarkFieldCustomTypeFailure-4 432 432 +0.00% BenchmarkFieldOrTagSuccess-4 4 4 +0.00% BenchmarkFieldOrTagFailure-4 448 448 +0.00% BenchmarkStructLevelValidationSuccess-4 160 160 +0.00% BenchmarkStructLevelValidationFailure-4 160 160 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 36 36 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 640 640 +0.00% BenchmarkStructPartialSuccess-4 336 336 +0.00% BenchmarkStructPartialFailure-4 794 794 +0.00% BenchmarkStructExceptSuccess-4 314 314 +0.00% BenchmarkStructExceptFailure-4 336 336 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 80 80 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 536 536 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 112 112 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 576 576 +0.00% BenchmarkStructSimpleSuccess-4 4 4 +0.00% BenchmarkStructSimpleFailure-4 640 640 +0.00% BenchmarkStructSimpleSuccessParallel-4 4 4 +0.00% BenchmarkStructSimpleFailureParallel-4 640 640 +0.00% BenchmarkStructComplexSuccess-4 244 244 +0.00% BenchmarkStructComplexFailure-4 3608 3608 +0.00% BenchmarkStructComplexSuccessParallel-4 244 244 +0.00% BenchmarkStructComplexFailureParallel-4 3608 3608 +0.00% ```
8 years ago
current.typeof = typeStructOnly
continue
case noStructLevelTag:
gain another 5% on average by changing tag type from bool's to enum ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 117 116 -0.85% BenchmarkFieldFailure-4 675 651 -3.56% BenchmarkFieldDiveSuccess-4 2518 2418 -3.97% BenchmarkFieldDiveFailure-4 3096 3011 -2.75% BenchmarkFieldCustomTypeSuccess-4 319 297 -6.90% BenchmarkFieldCustomTypeFailure-4 688 680 -1.16% BenchmarkFieldOrTagSuccess-4 1251 1176 -6.00% BenchmarkFieldOrTagFailure-4 1090 1073 -1.56% BenchmarkStructLevelValidationSuccess-4 558 567 +1.61% BenchmarkStructLevelValidationFailure-4 608 562 -7.57% BenchmarkStructSimpleCustomTypeSuccess-4 702 636 -9.40% BenchmarkStructSimpleCustomTypeFailure-4 1380 1295 -6.16% BenchmarkStructPartialSuccess-4 1139 1058 -7.11% BenchmarkStructPartialFailure-4 1760 1648 -6.36% BenchmarkStructExceptSuccess-4 951 917 -3.58% BenchmarkStructExceptFailure-4 1147 1085 -5.41% BenchmarkStructSimpleCrossFieldSuccess-4 873 783 -10.31% BenchmarkStructSimpleCrossFieldFailure-4 1478 1384 -6.36% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1328 1273 -4.14% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 1949 1896 -2.72% BenchmarkStructSimpleSuccess-4 559 523 -6.44% BenchmarkStructSimpleFailure-4 1334 1311 -1.72% BenchmarkStructSimpleSuccessParallel-4 148 137 -7.43% BenchmarkStructSimpleFailureParallel-4 631 591 -6.34% BenchmarkStructComplexSuccess-4 3476 3500 +0.69% BenchmarkStructComplexFailure-4 8467 8406 -0.72% BenchmarkStructComplexSuccessParallel-4 1098 1012 -7.83% BenchmarkStructComplexFailureParallel-4 3113 3121 +0.26% benchmark old allocs new allocs delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 4 4 +0.00% BenchmarkFieldDiveSuccess-4 28 28 +0.00% BenchmarkFieldDiveFailure-4 32 32 +0.00% BenchmarkFieldCustomTypeSuccess-4 2 2 +0.00% BenchmarkFieldCustomTypeFailure-4 4 4 +0.00% BenchmarkFieldOrTagSuccess-4 1 1 +0.00% BenchmarkFieldOrTagFailure-4 6 6 +0.00% BenchmarkStructLevelValidationSuccess-4 5 5 +0.00% BenchmarkStructLevelValidationFailure-4 5 5 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 3 3 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 9 9 +0.00% BenchmarkStructPartialSuccess-4 9 9 +0.00% BenchmarkStructPartialFailure-4 14 14 +0.00% BenchmarkStructExceptSuccess-4 7 7 +0.00% BenchmarkStructExceptFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 4 4 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 7 7 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 12 12 +0.00% BenchmarkStructSimpleSuccess-4 1 1 +0.00% BenchmarkStructSimpleFailure-4 9 9 +0.00% BenchmarkStructSimpleSuccessParallel-4 1 1 +0.00% BenchmarkStructSimpleFailureParallel-4 9 9 +0.00% BenchmarkStructComplexSuccess-4 15 15 +0.00% BenchmarkStructComplexFailure-4 60 60 +0.00% BenchmarkStructComplexSuccessParallel-4 15 15 +0.00% BenchmarkStructComplexFailureParallel-4 60 60 +0.00% benchmark old bytes new bytes delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 432 432 +0.00% BenchmarkFieldDiveSuccess-4 464 464 +0.00% BenchmarkFieldDiveFailure-4 896 896 +0.00% BenchmarkFieldCustomTypeSuccess-4 32 32 +0.00% BenchmarkFieldCustomTypeFailure-4 432 432 +0.00% BenchmarkFieldOrTagSuccess-4 4 4 +0.00% BenchmarkFieldOrTagFailure-4 448 448 +0.00% BenchmarkStructLevelValidationSuccess-4 160 160 +0.00% BenchmarkStructLevelValidationFailure-4 160 160 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 36 36 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 640 640 +0.00% BenchmarkStructPartialSuccess-4 336 336 +0.00% BenchmarkStructPartialFailure-4 794 794 +0.00% BenchmarkStructExceptSuccess-4 314 314 +0.00% BenchmarkStructExceptFailure-4 336 336 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 80 80 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 536 536 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 112 112 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 576 576 +0.00% BenchmarkStructSimpleSuccess-4 4 4 +0.00% BenchmarkStructSimpleFailure-4 640 640 +0.00% BenchmarkStructSimpleSuccessParallel-4 4 4 +0.00% BenchmarkStructSimpleFailureParallel-4 640 640 +0.00% BenchmarkStructComplexSuccess-4 244 244 +0.00% BenchmarkStructComplexFailure-4 3608 3608 +0.00% BenchmarkStructComplexSuccessParallel-4 244 244 +0.00% BenchmarkStructComplexFailureParallel-4 3608 3608 +0.00% ```
8 years ago
current.typeof = typeNoStructLevel
continue
default:
if t == isdefault {
current.typeof = typeIsDefault
}
// if a pipe character is needed within the param you must use the utf8Pipe representation "0x7C"
orVals := strings.Split(t, orSeparator)
for j := 0; j < len(orVals); j++ {
vals := strings.SplitN(orVals[j], tagKeySeparator, 2)
if noAlias {
alias = vals[0]
current.aliasTag = alias
} else {
current.actualAliasTag = t
}
if j > 0 {
current.next = &cTag{aliasTag: alias, actualAliasTag: current.actualAliasTag, hasAlias: hasAlias, hasTag: true}
current = current.next
}
current.hasParam = len(vals) > 1
code cleanup + add missing tag cache with FieldWith func Still looking good: ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 167 119 -28.74% BenchmarkFieldFailure-4 701 650 -7.28% BenchmarkFieldDiveSuccess-4 2937 2482 -15.49% BenchmarkFieldDiveFailure-4 3536 3046 -13.86% BenchmarkFieldCustomTypeSuccess-4 341 296 -13.20% BenchmarkFieldCustomTypeFailure-4 679 666 -1.91% BenchmarkFieldOrTagSuccess-4 1157 1124 -2.85% BenchmarkFieldOrTagFailure-4 1109 1036 -6.58% BenchmarkStructLevelValidationSuccess-4 694 554 -20.17% BenchmarkStructLevelValidationFailure-4 1311 558 -57.44% BenchmarkStructSimpleCustomTypeSuccess-4 894 654 -26.85% BenchmarkStructSimpleCustomTypeFailure-4 1496 1286 -14.04% BenchmarkStructPartialSuccess-4 1229 1062 -13.59% BenchmarkStructPartialFailure-4 1838 1639 -10.83% BenchmarkStructExceptSuccess-4 961 919 -4.37% BenchmarkStructExceptFailure-4 1218 1072 -11.99% BenchmarkStructSimpleCrossFieldSuccess-4 954 800 -16.14% BenchmarkStructSimpleCrossFieldFailure-4 1569 1372 -12.56% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1588 1274 -19.77% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 2217 1901 -14.25% BenchmarkStructSimpleSuccess-4 925 512 -44.65% BenchmarkStructSimpleFailure-4 1650 1318 -20.12% BenchmarkStructSimpleSuccessParallel-4 261 144 -44.83% BenchmarkStructSimpleFailureParallel-4 758 581 -23.35% BenchmarkStructComplexSuccess-4 5868 3451 -41.19% BenchmarkStructComplexFailure-4 10767 8351 -22.44% BenchmarkStructComplexSuccessParallel-4 1559 1065 -31.69% BenchmarkStructComplexFailureParallel-4 3747 2916 -22.18% ```
8 years ago
current.tag = vals[0]
if len(current.tag) == 0 {
panic(strings.TrimSpace(fmt.Sprintf(invalidValidation, fieldName)))
}
if wrapper, ok := v.validations[current.tag]; ok {
current.fn = wrapper.fn
current.runValidationWhenNil = wrapper.runValidatinOnNil
} else {
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, current.tag, fieldName)))
}
gain another 5% on average by changing tag type from bool's to enum ``` benchmark old ns/op new ns/op delta BenchmarkFieldSuccess-4 117 116 -0.85% BenchmarkFieldFailure-4 675 651 -3.56% BenchmarkFieldDiveSuccess-4 2518 2418 -3.97% BenchmarkFieldDiveFailure-4 3096 3011 -2.75% BenchmarkFieldCustomTypeSuccess-4 319 297 -6.90% BenchmarkFieldCustomTypeFailure-4 688 680 -1.16% BenchmarkFieldOrTagSuccess-4 1251 1176 -6.00% BenchmarkFieldOrTagFailure-4 1090 1073 -1.56% BenchmarkStructLevelValidationSuccess-4 558 567 +1.61% BenchmarkStructLevelValidationFailure-4 608 562 -7.57% BenchmarkStructSimpleCustomTypeSuccess-4 702 636 -9.40% BenchmarkStructSimpleCustomTypeFailure-4 1380 1295 -6.16% BenchmarkStructPartialSuccess-4 1139 1058 -7.11% BenchmarkStructPartialFailure-4 1760 1648 -6.36% BenchmarkStructExceptSuccess-4 951 917 -3.58% BenchmarkStructExceptFailure-4 1147 1085 -5.41% BenchmarkStructSimpleCrossFieldSuccess-4 873 783 -10.31% BenchmarkStructSimpleCrossFieldFailure-4 1478 1384 -6.36% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 1328 1273 -4.14% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 1949 1896 -2.72% BenchmarkStructSimpleSuccess-4 559 523 -6.44% BenchmarkStructSimpleFailure-4 1334 1311 -1.72% BenchmarkStructSimpleSuccessParallel-4 148 137 -7.43% BenchmarkStructSimpleFailureParallel-4 631 591 -6.34% BenchmarkStructComplexSuccess-4 3476 3500 +0.69% BenchmarkStructComplexFailure-4 8467 8406 -0.72% BenchmarkStructComplexSuccessParallel-4 1098 1012 -7.83% BenchmarkStructComplexFailureParallel-4 3113 3121 +0.26% benchmark old allocs new allocs delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 4 4 +0.00% BenchmarkFieldDiveSuccess-4 28 28 +0.00% BenchmarkFieldDiveFailure-4 32 32 +0.00% BenchmarkFieldCustomTypeSuccess-4 2 2 +0.00% BenchmarkFieldCustomTypeFailure-4 4 4 +0.00% BenchmarkFieldOrTagSuccess-4 1 1 +0.00% BenchmarkFieldOrTagFailure-4 6 6 +0.00% BenchmarkStructLevelValidationSuccess-4 5 5 +0.00% BenchmarkStructLevelValidationFailure-4 5 5 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 3 3 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 9 9 +0.00% BenchmarkStructPartialSuccess-4 9 9 +0.00% BenchmarkStructPartialFailure-4 14 14 +0.00% BenchmarkStructExceptSuccess-4 7 7 +0.00% BenchmarkStructExceptFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 4 4 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 9 9 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 7 7 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 12 12 +0.00% BenchmarkStructSimpleSuccess-4 1 1 +0.00% BenchmarkStructSimpleFailure-4 9 9 +0.00% BenchmarkStructSimpleSuccessParallel-4 1 1 +0.00% BenchmarkStructSimpleFailureParallel-4 9 9 +0.00% BenchmarkStructComplexSuccess-4 15 15 +0.00% BenchmarkStructComplexFailure-4 60 60 +0.00% BenchmarkStructComplexSuccessParallel-4 15 15 +0.00% BenchmarkStructComplexFailureParallel-4 60 60 +0.00% benchmark old bytes new bytes delta BenchmarkFieldSuccess-4 0 0 +0.00% BenchmarkFieldFailure-4 432 432 +0.00% BenchmarkFieldDiveSuccess-4 464 464 +0.00% BenchmarkFieldDiveFailure-4 896 896 +0.00% BenchmarkFieldCustomTypeSuccess-4 32 32 +0.00% BenchmarkFieldCustomTypeFailure-4 432 432 +0.00% BenchmarkFieldOrTagSuccess-4 4 4 +0.00% BenchmarkFieldOrTagFailure-4 448 448 +0.00% BenchmarkStructLevelValidationSuccess-4 160 160 +0.00% BenchmarkStructLevelValidationFailure-4 160 160 +0.00% BenchmarkStructSimpleCustomTypeSuccess-4 36 36 +0.00% BenchmarkStructSimpleCustomTypeFailure-4 640 640 +0.00% BenchmarkStructPartialSuccess-4 336 336 +0.00% BenchmarkStructPartialFailure-4 794 794 +0.00% BenchmarkStructExceptSuccess-4 314 314 +0.00% BenchmarkStructExceptFailure-4 336 336 +0.00% BenchmarkStructSimpleCrossFieldSuccess-4 80 80 +0.00% BenchmarkStructSimpleCrossFieldFailure-4 536 536 +0.00% BenchmarkStructSimpleCrossStructCrossFieldSuccess-4 112 112 +0.00% BenchmarkStructSimpleCrossStructCrossFieldFailure-4 576 576 +0.00% BenchmarkStructSimpleSuccess-4 4 4 +0.00% BenchmarkStructSimpleFailure-4 640 640 +0.00% BenchmarkStructSimpleSuccessParallel-4 4 4 +0.00% BenchmarkStructSimpleFailureParallel-4 640 640 +0.00% BenchmarkStructComplexSuccess-4 244 244 +0.00% BenchmarkStructComplexFailure-4 3608 3608 +0.00% BenchmarkStructComplexSuccessParallel-4 244 244 +0.00% BenchmarkStructComplexFailureParallel-4 3608 3608 +0.00% ```
8 years ago
if len(orVals) > 1 {
current.typeof = typeOr
}
if len(vals) > 1 {
current.param = strings.Replace(strings.Replace(vals[1], utf8HexComma, ",", -1), utf8Pipe, "|", -1)
}
}
current.isBlockEnd = true
}
}
return
}
func (v *Validate) fetchCacheTag(tag string) *cTag {
// find cached tag
ctag, found := v.tagCache.Get(tag)
if !found {
v.tagCache.lock.Lock()
defer v.tagCache.lock.Unlock()
// could have been multiple trying to access, but once first is done this ensures tag
// isn't parsed again.
ctag, found = v.tagCache.Get(tag)
if !found {
ctag, _ = v.parseFieldTagsRecursive(tag, "", "", false)
v.tagCache.Set(tag, ctag)
}
}
return ctag
}