Update godeps for etcd 3.0.4
This commit is contained in:
124
vendor/github.com/ugorji/go/codec/encode.go
generated
vendored
124
vendor/github.com/ugorji/go/codec/encode.go
generated
vendored
@@ -110,15 +110,6 @@ type EncodeOptions struct {
|
||||
//
|
||||
Canonical bool
|
||||
|
||||
// CheckCircularRef controls whether we check for circular references
|
||||
// and error fast during an encode.
|
||||
//
|
||||
// If enabled, an error is received if a pointer to a struct
|
||||
// references itself either directly or through one of its fields (iteratively).
|
||||
//
|
||||
// This is opt-in, as there may be a performance hit to checking circular references.
|
||||
CheckCircularRef bool
|
||||
|
||||
// AsSymbols defines what should be encoded as symbols.
|
||||
//
|
||||
// Encoding as symbols can reduce the encoded size significantly.
|
||||
@@ -473,7 +464,7 @@ func (f *encFnInfo) kSlice(rv reflect.Value) {
|
||||
for j := 0; j < l; j++ {
|
||||
if cr != nil {
|
||||
if ti.mbs {
|
||||
if j%2 == 0 {
|
||||
if l%2 == 0 {
|
||||
cr.sendContainerState(containerMapKey)
|
||||
} else {
|
||||
cr.sendContainerState(containerMapValue)
|
||||
@@ -512,7 +503,7 @@ func (f *encFnInfo) kStruct(rv reflect.Value) {
|
||||
newlen := len(fti.sfi)
|
||||
|
||||
// Use sync.Pool to reduce allocating slices unnecessarily.
|
||||
// The cost of sync.Pool is less than the cost of new allocation.
|
||||
// The cost of the occasional locking is less than the cost of new allocation.
|
||||
pool, poolv, fkvs := encStructPoolGet(newlen)
|
||||
|
||||
// if toMap, use the sorted array. If toArray, use unsorted array (to match sequence in struct)
|
||||
@@ -523,6 +514,11 @@ func (f *encFnInfo) kStruct(rv reflect.Value) {
|
||||
var kv stringRv
|
||||
for _, si := range tisfi {
|
||||
kv.r = si.field(rv, false)
|
||||
// if si.i != -1 {
|
||||
// rvals[newlen] = rv.Field(int(si.i))
|
||||
// } else {
|
||||
// rvals[newlen] = rv.FieldByIndex(si.is)
|
||||
// }
|
||||
if toMap {
|
||||
if si.omitEmpty && isEmptyValue(kv.r) {
|
||||
continue
|
||||
@@ -600,15 +596,13 @@ func (f *encFnInfo) kStruct(rv reflect.Value) {
|
||||
// f.e.encodeValue(rv.Elem())
|
||||
// }
|
||||
|
||||
// func (f *encFnInfo) kInterface(rv reflect.Value) {
|
||||
// println("kInterface called")
|
||||
// debug.PrintStack()
|
||||
// if rv.IsNil() {
|
||||
// f.e.e.EncodeNil()
|
||||
// return
|
||||
// }
|
||||
// f.e.encodeValue(rv.Elem(), nil)
|
||||
// }
|
||||
func (f *encFnInfo) kInterface(rv reflect.Value) {
|
||||
if rv.IsNil() {
|
||||
f.e.e.EncodeNil()
|
||||
return
|
||||
}
|
||||
f.e.encodeValue(rv.Elem(), nil)
|
||||
}
|
||||
|
||||
func (f *encFnInfo) kMap(rv reflect.Value) {
|
||||
ee := f.e.e
|
||||
@@ -883,7 +877,6 @@ type Encoder struct {
|
||||
// as the handler MAY need to do some coordination.
|
||||
w encWriter
|
||||
s []encRtidFn
|
||||
ci set
|
||||
be bool // is binary encoding
|
||||
js bool // is json handle
|
||||
|
||||
@@ -1140,23 +1133,20 @@ func (e *Encoder) encode(iv interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Encoder) preEncodeValue(rv reflect.Value) (rv2 reflect.Value, sptr uintptr, proceed bool) {
|
||||
func (e *Encoder) encodeI(iv interface{}, checkFastpath, checkCodecSelfer bool) {
|
||||
if rv, proceed := e.preEncodeValue(reflect.ValueOf(iv)); proceed {
|
||||
rt := rv.Type()
|
||||
rtid := reflect.ValueOf(rt).Pointer()
|
||||
fn := e.getEncFn(rtid, rt, checkFastpath, checkCodecSelfer)
|
||||
fn.f(&fn.i, rv)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Encoder) preEncodeValue(rv reflect.Value) (rv2 reflect.Value, proceed bool) {
|
||||
// use a goto statement instead of a recursive function for ptr/interface.
|
||||
TOP:
|
||||
switch rv.Kind() {
|
||||
case reflect.Ptr:
|
||||
if rv.IsNil() {
|
||||
e.e.EncodeNil()
|
||||
return
|
||||
}
|
||||
rv = rv.Elem()
|
||||
if e.h.CheckCircularRef && rv.Kind() == reflect.Struct {
|
||||
// TODO: Movable pointers will be an issue here. Future problem.
|
||||
sptr = rv.UnsafeAddr()
|
||||
break TOP
|
||||
}
|
||||
goto TOP
|
||||
case reflect.Interface:
|
||||
case reflect.Ptr, reflect.Interface:
|
||||
if rv.IsNil() {
|
||||
e.e.EncodeNil()
|
||||
return
|
||||
@@ -1173,40 +1163,18 @@ TOP:
|
||||
return
|
||||
}
|
||||
|
||||
proceed = true
|
||||
rv2 = rv
|
||||
return
|
||||
}
|
||||
|
||||
func (e *Encoder) doEncodeValue(rv reflect.Value, fn *encFn, sptr uintptr,
|
||||
checkFastpath, checkCodecSelfer bool) {
|
||||
if sptr != 0 {
|
||||
if (&e.ci).add(sptr) {
|
||||
e.errorf("circular reference found: # %d", sptr)
|
||||
}
|
||||
}
|
||||
if fn == nil {
|
||||
rt := rv.Type()
|
||||
rtid := reflect.ValueOf(rt).Pointer()
|
||||
// fn = e.getEncFn(rtid, rt, true, true)
|
||||
fn = e.getEncFn(rtid, rt, checkFastpath, checkCodecSelfer)
|
||||
}
|
||||
fn.f(&fn.i, rv)
|
||||
if sptr != 0 {
|
||||
(&e.ci).remove(sptr)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeI(iv interface{}, checkFastpath, checkCodecSelfer bool) {
|
||||
if rv, sptr, proceed := e.preEncodeValue(reflect.ValueOf(iv)); proceed {
|
||||
e.doEncodeValue(rv, nil, sptr, checkFastpath, checkCodecSelfer)
|
||||
}
|
||||
return rv, true
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeValue(rv reflect.Value, fn *encFn) {
|
||||
// if a valid fn is passed, it MUST BE for the dereferenced type of rv
|
||||
if rv, sptr, proceed := e.preEncodeValue(rv); proceed {
|
||||
e.doEncodeValue(rv, fn, sptr, true, true)
|
||||
if rv, proceed := e.preEncodeValue(rv); proceed {
|
||||
if fn == nil {
|
||||
rt := rv.Type()
|
||||
rtid := reflect.ValueOf(rt).Pointer()
|
||||
fn = e.getEncFn(rtid, rt, true, true)
|
||||
}
|
||||
fn.f(&fn.i, rv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1266,7 +1234,7 @@ func (e *Encoder) getEncFn(rtid uintptr, rt reflect.Type, checkFastpath, checkCo
|
||||
} else {
|
||||
rk := rt.Kind()
|
||||
if fastpathEnabled && checkFastpath && (rk == reflect.Map || rk == reflect.Slice) {
|
||||
if rt.PkgPath() == "" { // un-named slice or map
|
||||
if rt.PkgPath() == "" {
|
||||
if idx := fastpathAV.index(rtid); idx != -1 {
|
||||
fn.f = fastpathAV[idx].encfn
|
||||
}
|
||||
@@ -1316,11 +1284,10 @@ func (e *Encoder) getEncFn(rtid uintptr, rt reflect.Type, checkFastpath, checkCo
|
||||
fn.f = (*encFnInfo).kSlice
|
||||
case reflect.Struct:
|
||||
fn.f = (*encFnInfo).kStruct
|
||||
// reflect.Ptr and reflect.Interface are handled already by preEncodeValue
|
||||
// case reflect.Ptr:
|
||||
// fn.f = (*encFnInfo).kPtr
|
||||
// case reflect.Interface:
|
||||
// fn.f = (*encFnInfo).kInterface
|
||||
case reflect.Interface:
|
||||
fn.f = (*encFnInfo).kInterface
|
||||
case reflect.Map:
|
||||
fn.f = (*encFnInfo).kMap
|
||||
default:
|
||||
@@ -1386,6 +1353,25 @@ func encStructPoolGet(newlen int) (p *sync.Pool, v interface{}, s []stringRv) {
|
||||
// panic(errors.New("encStructPoolLen must be equal to 4")) // defensive, in case it is changed
|
||||
// }
|
||||
// idxpool := newlen / 8
|
||||
|
||||
// if pool == nil {
|
||||
// fkvs = make([]stringRv, newlen)
|
||||
// } else {
|
||||
// poolv = pool.Get()
|
||||
// switch vv := poolv.(type) {
|
||||
// case *[8]stringRv:
|
||||
// fkvs = vv[:newlen]
|
||||
// case *[16]stringRv:
|
||||
// fkvs = vv[:newlen]
|
||||
// case *[32]stringRv:
|
||||
// fkvs = vv[:newlen]
|
||||
// case *[64]stringRv:
|
||||
// fkvs = vv[:newlen]
|
||||
// case *[128]stringRv:
|
||||
// fkvs = vv[:newlen]
|
||||
// }
|
||||
// }
|
||||
|
||||
if newlen <= 8 {
|
||||
p = &encStructPool[0]
|
||||
v = p.Get()
|
||||
|
Reference in New Issue
Block a user