saving some bytes uint8 vs int

pull/256/head
joeybloggs 9 years ago
parent b2c8f66e7b
commit 3e196d49c6
  1. 8
      cache.go
  2. 10
      errors.go
  3. 8
      struct_level.go
  4. 20
      validator.go

@ -153,7 +153,13 @@ func (v *Validate) extractStructCache(current reflect.Value, sName string) *cStr
ctag = new(cTag)
}
cs.fields[i] = &cField{idx: i, name: fld.Name, altName: customName, cTags: ctag, namesEqual: fld.Name == customName}
cs.fields[i] = &cField{
idx: i,
name: fld.Name,
altName: customName,
cTags: ctag,
namesEqual: fld.Name == customName,
}
}
v.structCache.Set(typ, cs)

@ -132,10 +132,8 @@ type fieldError struct {
actualTag string
ns string
structNs string
fieldLen int
structfieldLen int
// field string
// structField string
fieldLen uint8
structfieldLen uint8
value interface{}
param string
kind reflect.Kind
@ -169,13 +167,13 @@ func (fe *fieldError) StructNamespace() string {
// fields actual name.
func (fe *fieldError) Field() string {
// return fe.field
return fe.ns[len(fe.ns)-fe.fieldLen:]
return fe.ns[len(fe.ns)-int(fe.fieldLen):]
}
// returns the fields actual name from the struct, when able to determine.
func (fe *fieldError) StructField() string {
// return fe.structField
return fe.structNs[len(fe.structNs)-fe.structfieldLen:]
return fe.structNs[len(fe.structNs)-int(fe.structfieldLen):]
}
// Value returns the actual fields value in case needed for creating the error

@ -121,8 +121,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
actualTag: tag,
ns: v.str1,
structNs: v.str2,
fieldLen: len(fieldName),
structfieldLen: len(structFieldName),
fieldLen: uint8(len(fieldName)),
structfieldLen: uint8(len(structFieldName)),
param: param,
kind: kind,
},
@ -136,8 +136,8 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
actualTag: tag,
ns: v.str1,
structNs: v.str2,
fieldLen: len(fieldName),
structfieldLen: len(structFieldName),
fieldLen: uint8(len(fieldName)),
structfieldLen: uint8(len(structFieldName)),
value: fv.Interface(),
param: param,
kind: kind,

@ -117,8 +117,8 @@ func (v *validate) traverseField(parent reflect.Value, current reflect.Value, ns
actualTag: ct.tag,
ns: v.str1,
structNs: v.str2,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
fieldLen: uint8(len(cf.altName)),
structfieldLen: uint8(len(cf.name)),
param: ct.param,
kind: kind,
},
@ -133,8 +133,8 @@ func (v *validate) traverseField(parent reflect.Value, current reflect.Value, ns
actualTag: ct.tag,
ns: v.str1,
structNs: v.str2,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
fieldLen: uint8(len(cf.altName)),
structfieldLen: uint8(len(cf.name)),
value: current.Interface(),
param: ct.param,
kind: kind,
@ -327,8 +327,8 @@ OUTER:
actualTag: ct.actualAliasTag,
ns: v.str1,
structNs: v.str2,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
fieldLen: uint8(len(cf.altName)),
structfieldLen: uint8(len(cf.name)),
value: current.Interface(),
param: ct.param,
kind: kind,
@ -346,8 +346,8 @@ OUTER:
actualTag: tVal,
ns: v.str1,
structNs: v.str2,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
fieldLen: uint8(len(cf.altName)),
structfieldLen: uint8(len(cf.name)),
value: current.Interface(),
param: ct.param,
kind: kind,
@ -385,8 +385,8 @@ OUTER:
actualTag: ct.tag,
ns: v.str1,
structNs: v.str2,
fieldLen: len(cf.altName),
structfieldLen: len(cf.name),
fieldLen: uint8(len(cf.altName)),
structfieldLen: uint8(len(cf.name)),
value: current.Interface(),
param: ct.param,
kind: kind,

Loading…
Cancel
Save