Commit 6745433a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fc0cf8de
...@@ -403,8 +403,6 @@ func (o *OverflowCheck) PopChecked() bool { ...@@ -403,8 +403,6 @@ func (o *OverflowCheck) PopChecked() bool {
return popret return popret
} }
// Add and AddExpr update .checkSize accordingly, but only if overflow was not // Add and AddExpr update .checkSize accordingly, but only if overflow was not
// already marked as checked // already marked as checked
func (o *OverflowCheck) Add(n int) { func (o *OverflowCheck) Add(n int) {
...@@ -518,7 +516,6 @@ func (e *encoder) generatedCode() string { ...@@ -518,7 +516,6 @@ func (e *encoder) generatedCode() string {
return code.String() return code.String()
} }
// XXX place? naming?
// data = data[n:] // data = data[n:]
// n = 0 // n = 0
func (d *decoder) resetPos() { func (d *decoder) resetPos() {
...@@ -556,7 +553,7 @@ func (d *decoder) overflowCheck() { ...@@ -556,7 +553,7 @@ func (d *decoder) overflowCheck() {
d.bufDone.emit("if uint32(len(data)) < %v { goto overflow }", &d.overflow.checkSize) d.bufDone.emit("if uint32(len(data)) < %v { goto overflow }", &d.overflow.checkSize)
// if size for overflow check was only numeric - just // if size for overflow check was only numeric - just
// accumulate it at compile time // accumulate it at generation time
// //
// otherwise accumulate into var(nread) at runtime. // otherwise accumulate into var(nread) at runtime.
// we do not break runtime accumulation into numeric & symbolic // we do not break runtime accumulation into numeric & symbolic
...@@ -782,7 +779,7 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) { ...@@ -782,7 +779,7 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) {
e.emit("for i := 0; uint32(i) <l; i++ {") e.emit("for i := 0; uint32(i) <l; i++ {")
e.emit("a := &%s[i]", path) e.emit("a := &%s[i]", path)
codegenType("(*a)", typ.Elem(), obj, e) codegenType("(*a)", typ.Elem(), obj, e)
e.emit("data = data[%v:]", e.n) // XXX wrt slice of slice ? e.emit("data = data[%v:]", e.n)
e.emit("}") e.emit("}")
e.emit("}") e.emit("}")
e.n = 0 e.n = 0
...@@ -854,6 +851,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) { ...@@ -854,6 +851,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) {
e.genBasic("l", types.Typ[types.Uint32], nil) e.genBasic("l", types.Typ[types.Uint32], nil)
e.emit("data = data[%v:]", e.n) e.emit("data = data[%v:]", e.n)
e.n = 0 e.n = 0
// output keys in sorted order on the wire // output keys in sorted order on the wire
// (easier for debugging & deterministic for testing) // (easier for debugging & deterministic for testing)
e.emit("keyv := make([]%s, 0, l)", typeName(typ.Key())) e.emit("keyv := make([]%s, 0, l)", typeName(typ.Key()))
...@@ -861,6 +859,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) { ...@@ -861,6 +859,7 @@ func (e *encoder) genMap(path string, typ *types.Map, obj types.Object) {
e.emit(" keyv = append(keyv, key)") e.emit(" keyv = append(keyv, key)")
e.emit("}") e.emit("}")
e.emit("sort.Slice(keyv, func (i, j int) bool { return keyv[i] < keyv[j] })") e.emit("sort.Slice(keyv, func (i, j int) bool { return keyv[i] < keyv[j] })")
e.emit("for _, key := range keyv {") e.emit("for _, key := range keyv {")
codegenType("key", typ.Key(), obj, e) codegenType("key", typ.Key(), obj, e)
codegenType(fmt.Sprintf("%s[key]", path), typ.Elem(), obj, e) codegenType(fmt.Sprintf("%s[key]", path), typ.Elem(), obj, e)
...@@ -879,8 +878,7 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) { ...@@ -879,8 +878,7 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
// if size(key,item)==const - check overflow in one go // if size(key,item)==const - check overflow in one go
keySize, keyFixed := typeSizeFixed(typ.Key()) keySize, keyFixed := typeSizeFixed(typ.Key())
elemSize, elemFixed := typeSizeFixed(typ.Elem()) elemSize, elemFixed := typeSizeFixed(typ.Elem())
itemFixed := keyFixed && elemFixed if keyFixed && elemFixed {
if itemFixed {
d.overflowCheck() d.overflowCheck()
d.overflow.AddExpr("l * %v", keySize + elemSize) d.overflow.AddExpr("l * %v", keySize + elemSize)
d.overflow.PushChecked(true) d.overflow.PushChecked(true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment