Commit eaa81cd4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 487229da
......@@ -400,13 +400,13 @@ overflow:
// 9. AcceptIdentification
func (p *AcceptIdentification) NEOEncodedLen() int {
var size int
var size0 int
for i := 0; i < len(p.KnownMasterList); i++ {
a := &p.KnownMasterList[i]
size += 10 + len((*a).Address.Host)
size0 += 10 + len((*a).Address.Host)
}
return 30 + len(p.Primary.Host) + size
return 30 + len(p.Primary.Host) + size0
}
func (p *AcceptIdentification) NEOEncode(data []byte) {
......@@ -722,13 +722,13 @@ overflow:
// 19. AnswerPartitionTable
func (p *AnswerPartitionTable) NEOEncodedLen() int {
var size int
var size0 int
for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i]
size += 8 + len((*a).CellList)*8
size0 += 8 + len((*a).CellList)*8
}
return 12 + size
return 12 + size0
}
func (p *AnswerPartitionTable) NEOEncode(data []byte) {
......@@ -812,13 +812,13 @@ overflow:
// 20. NotifyPartitionTable
func (p *NotifyPartitionTable) NEOEncodedLen() int {
var size int
var size0 int
for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i]
size += 8 + len((*a).CellList)*8
size0 += 8 + len((*a).CellList)*8
}
return 12 + size
return 12 + size0
}
func (p *NotifyPartitionTable) NEOEncode(data []byte) {
......@@ -2596,13 +2596,13 @@ overflow:
// 58. AnswerPartitionList
func (p *AnswerPartitionList) NEOEncodedLen() int {
var size int
var size0 int
for i := 0; i < len(p.RowList); i++ {
a := &p.RowList[i]
size += 8 + len((*a).CellList)*8
size0 += 8 + len((*a).CellList)*8
}
return 12 + size
return 12 + size0
}
func (p *AnswerPartitionList) NEOEncode(data []byte) {
......@@ -2709,13 +2709,13 @@ overflow:
// 60. AnswerNodeList
func (p *AnswerNodeList) NEOEncodedLen() int {
var size int
var size0 int
for i := 0; i < len(p.NodeList); i++ {
a := &p.NodeList[i]
size += 26 + len((*a).Address.Host)
size0 += 26 + len((*a).Address.Host)
}
return 4 + size
return 4 + size0
}
func (p *AnswerNodeList) NEOEncode(data []byte) {
......@@ -2921,13 +2921,13 @@ overflow:
// 64. NotifyNodeInformation
func (p *NotifyNodeInformation) NEOEncodedLen() int {
var size int
var size0 int
for i := 0; i < len(p.NodeList); i++ {
a := &p.NodeList[i]
size += 26 + len((*a).Address.Host)
size0 += 26 + len((*a).Address.Host)
}
return 4 + size
return 4 + size0
}
func (p *NotifyNodeInformation) NEOEncode(data []byte) {
......
......@@ -251,16 +251,25 @@ type sizer struct {
symLenv []string // symbolic part of size
varN int // suffix to add to variables (size0, size1, ...) - for nested computations
varSizeUsed bool // whether var size was used
varUsed map[string]bool // whether a variable was used
coderForFunc
}
// get variable name for varname
func (s *sizer) var_(varname string) string {
func (s *sizer) var__(varname string) string {
return fmt.Sprintf("%s%d", varname, s.varN)
}
func (s *sizer) var_(varname string) string {
varnameX := s.var__(varname)
if s.varUsed == nil {
s.varUsed = make(map[string]bool)
}
s.varUsed[varname] = true
return varnameX
}
// create new sizer for subsize calculation (e.g. for loop)
func (s *sizer) subSizer() *sizer {
return &sizer{varN: s.varN + 1}
......@@ -289,8 +298,8 @@ func (s *sizer) resultExpr() string {
if len(s.symLenv) > 0 {
size += " + " + strings.Join(s.symLenv, " + ")
}
if s.varSizeUsed {
size += " + size"
if s.varUsed["size"] {
size += " + " + s.var__("size")
}
return size
}
......@@ -301,8 +310,8 @@ func (s *sizer) generatedCode() string {
if s.recvName != "" {
code.emit("func (%s *%s) NEOEncodedLen() int {", s.recvName, s.typeName)
}
if s.varSizeUsed {
code.emit("var size int")
if s.varUsed["size"] {
code.emit("var %s int", s.var__("size"))
}
code.Write(s.Bytes()) // XXX -> s.buf.Bytes() ?
......@@ -440,7 +449,6 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
return
}
s.varSizeUsed = true
s.n += 4
s.emit("for i := 0; i < len(%v); i++ {", path)
s.emit("a := &%s[i]", path)
......@@ -449,7 +457,7 @@ func (s *sizer) genSlice(path string, typ *types.Slice, obj types.Object) {
codegenType("(*a)", typ.Elem(), obj, sloop)
// FIXME vvv if symLenv is ø; -> turn into "result" function
s.emit(sloop.generatedCode())
s.emit("size += %v", sloop.resultExpr())
s.emit("%v += %v", s.var_("size"), sloop.resultExpr())
s.emit("}")
}
......@@ -505,13 +513,11 @@ func (s *sizer) genMap(path string, typ *types.Map, obj types.Object) {
}
panic("UNTESTED")
s.varSizeUsed = true
s.n += 4
s.emit("size += %v", s.n)
s.emit("for key := range %s {", path)
codegenType("key", typ.Key(), obj, s)
codegenType(fmt.Sprintf("%s[key]", path), typ.Elem(), obj, s)
s.emit("size += %v", s.n)
s.emit("%v += %v", s.var_("size"), s.n)
s.emit("}")
}
......
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