Commit cd8d5919 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e14f832e
...@@ -1189,20 +1189,12 @@ func (p *FinishTransaction) NEOEncodedLen() int { ...@@ -1189,20 +1189,12 @@ func (p *FinishTransaction) NEOEncodedLen() int {
{ {
l := uint32(len(p.OIDList)) l := uint32(len(p.OIDList))
size += 12 size += 12
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.OIDList[i]
_ = a
size += 8
}
} }
{ {
l := uint32(len(p.CheckedList)) l := uint32(len(p.CheckedList))
size += 4 size += 4
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.CheckedList[i]
_ = a
size += 8
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -1362,11 +1354,7 @@ func (p *InvalidateObjects) NEOEncodedLen() int { ...@@ -1362,11 +1354,7 @@ func (p *InvalidateObjects) NEOEncodedLen() int {
{ {
l := uint32(len(p.OidList)) l := uint32(len(p.OidList))
size += 12 size += 12
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.OidList[i]
_ = a
size += 8
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -1456,11 +1444,7 @@ func (p *AnswerGenerateOIDs) NEOEncodedLen() int { ...@@ -1456,11 +1444,7 @@ func (p *AnswerGenerateOIDs) NEOEncodedLen() int {
{ {
l := uint32(len(p.OidList)) l := uint32(len(p.OidList))
size += 4 size += 4
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.OidList[i]
_ = a
size += 8
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -1506,11 +1490,7 @@ func (p *StoreObject) NEOEncodedLen() int { ...@@ -1506,11 +1490,7 @@ func (p *StoreObject) NEOEncodedLen() int {
{ {
l := uint32(len(p.Data)) l := uint32(len(p.Data))
size += 41 size += 41
for i := 0; uint32(i) < l; i++ { size += l * 1
a := &p.Data[i]
_ = a
size += 1
}
} }
return int(size) + 17 return int(size) + 17
} }
...@@ -1666,11 +1646,7 @@ func (p *StoreTransaction) NEOEncodedLen() int { ...@@ -1666,11 +1646,7 @@ func (p *StoreTransaction) NEOEncodedLen() int {
{ {
l := uint32(len(p.OidList)) l := uint32(len(p.OidList))
size += 4 size += 4
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.OidList[i]
_ = a
size += 8
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -1815,11 +1791,7 @@ func (p *AnswerGetObject) NEOEncodedLen() int { ...@@ -1815,11 +1791,7 @@ func (p *AnswerGetObject) NEOEncodedLen() int {
{ {
l := uint32(len(p.Data)) l := uint32(len(p.Data))
size += 49 size += 49
for i := 0; uint32(i) < l; i++ { size += l * 1
a := &p.Data[i]
_ = a
size += 1
}
} }
return int(size) + 8 return int(size) + 8
} }
...@@ -1940,11 +1912,7 @@ func (p *AnswerTIDList) NEOEncodedLen() int { ...@@ -1940,11 +1912,7 @@ func (p *AnswerTIDList) NEOEncodedLen() int {
{ {
l := uint32(len(p.TIDList)) l := uint32(len(p.TIDList))
size += 4 size += 4
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.TIDList[i]
_ = a
size += 8
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -2017,11 +1985,7 @@ func (p *AnswerTIDListFrom) NEOEncodedLen() int { ...@@ -2017,11 +1985,7 @@ func (p *AnswerTIDListFrom) NEOEncodedLen() int {
{ {
l := uint32(len(p.TidList)) l := uint32(len(p.TidList))
size += 4 size += 4
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.TidList[i]
_ = a
size += 8
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -2100,11 +2064,7 @@ func (p *AnswerTransactionInformation) NEOEncodedLen() int { ...@@ -2100,11 +2064,7 @@ func (p *AnswerTransactionInformation) NEOEncodedLen() int {
{ {
l := uint32(len(p.OidList)) l := uint32(len(p.OidList))
size += 5 size += 5
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.OidList[i]
_ = a
size += 8
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -2520,11 +2480,7 @@ func (p *AddPendingNodes) NEOEncodedLen() int { ...@@ -2520,11 +2480,7 @@ func (p *AddPendingNodes) NEOEncodedLen() int {
{ {
l := uint32(len(p.UUIDList)) l := uint32(len(p.UUIDList))
size += 4 size += 4
for i := 0; uint32(i) < l; i++ { size += l * 4
a := &p.UUIDList[i]
_ = a
size += 4
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -2570,11 +2526,7 @@ func (p *TweakPartitionTable) NEOEncodedLen() int { ...@@ -2570,11 +2526,7 @@ func (p *TweakPartitionTable) NEOEncodedLen() int {
{ {
l := uint32(len(p.UUIDList)) l := uint32(len(p.UUIDList))
size += 4 size += 4
for i := 0; uint32(i) < l; i++ { size += l * 4
a := &p.UUIDList[i]
_ = a
size += 4
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -2781,11 +2733,7 @@ func (p *ObjectUndoSerial) NEOEncodedLen() int { ...@@ -2781,11 +2733,7 @@ func (p *ObjectUndoSerial) NEOEncodedLen() int {
{ {
l := uint32(len(p.OidList)) l := uint32(len(p.OidList))
size += 28 size += 28
for i := 0; uint32(i) < l; i++ { size += l * 8
a := &p.OidList[i]
_ = a
size += 8
}
} }
return int(size) + 0 return int(size) + 0
} }
...@@ -3398,11 +3346,7 @@ func (p *PartitionCorrupted) NEOEncodedLen() int { ...@@ -3398,11 +3346,7 @@ func (p *PartitionCorrupted) NEOEncodedLen() int {
{ {
l := uint32(len(p.CellList)) l := uint32(len(p.CellList))
size += 8 size += 8
for i := 0; uint32(i) < l; i++ { size += l * 4
a := &p.CellList[i]
_ = a
size += 4
}
} }
return int(size) + 0 return int(size) + 0
} }
......
...@@ -166,6 +166,20 @@ var basicTypes = map[types.BasicKind]basicCodec { ...@@ -166,6 +166,20 @@ var basicTypes = map[types.BasicKind]basicCodec {
types.Float64: {8, "float64_NEOEncode(%v, %v)", "float64_NEODecode(%v)"}, types.Float64: {8, "float64_NEOEncode(%v, %v)", "float64_NEODecode(%v)"},
} }
// does a type have fixed wire size and what it is
func typeSizeFixed(typ types.Type) (wireSize int, ok bool) {
switch u := typ.Underlying().(type) {
case *types.Basic:
basic, ok := basicTypes[u.Kind()]
if ok {
return basic.wireSize, ok
}
}
// not matched above - not fixed
return 0, false
}
// Buffer + bell & whistles // Buffer + bell & whistles
type Buffer struct { type Buffer struct {
...@@ -325,6 +339,10 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) { ...@@ -325,6 +339,10 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) {
} }
e.n = 0 e.n = 0
// TODO if size(item)==const - size update in one go // TODO if size(item)==const - size update in one go
elemSize, ok := typeSizeFixed(typ.Elem())
if e.SizeOnly && ok {
e.emit("size += l * %v", elemSize)
} else {
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)
...@@ -335,6 +353,7 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) { ...@@ -335,6 +353,7 @@ func (e *encoder) genSlice(path string, typ *types.Slice, obj types.Object) {
e.emit("size += %v", e.n) e.emit("size += %v", e.n)
} }
e.emit("}") e.emit("}")
}
// see vvv // see vvv
e.emit("}") e.emit("}")
e.n = 0 e.n = 0
......
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