Fix some VDLRead bugs and minor clean-up.
While I was implementing the reflect version of VDLRead, I
noticed some bugs in both the vdl.Value and codegen versions of
VDLRead, so I fixed them.
The codegen set/map version was wrong because it was
early-existing when the lenhint is 0, rather than calling
NextEntry until it returned done. The lenhint handling in
general was wrong for multiple types; we need to ensure we end up
with nil collections if there are no entries.
I also made the codegen version of array faster, by filling the
elem in directly, rather than using a temp variable. I changed
the vdl.Value version list to add support for our eventual world
where the LenHint really isn't set, and employed a simple growth
strategy.
I also noticed that the type compatibility checks we added make
our benchmarks 20% worse. We can deal with that later.
MultiPart: 4/4
Change-Id: I81ba17fb6535ce7f9bd97c9e1d767eda2d699a6f
diff --git a/go/src/v.io/x/sensorlog/internal/sbmodel/sbmodel.vdl.go b/go/src/v.io/x/sensorlog/internal/sbmodel/sbmodel.vdl.go
index 1537f6a..21628b0 100644
--- a/go/src/v.io/x/sensorlog/internal/sbmodel/sbmodel.vdl.go
+++ b/go/src/v.io/x/sensorlog/internal/sbmodel/sbmodel.vdl.go
@@ -150,7 +150,6 @@
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
}
- match := 0
for {
f, err := dec.NextField()
if err != nil {
@@ -158,12 +157,8 @@
}
switch f {
case "":
- if match == 0 && dec.Type().NumField() > 0 {
- return fmt.Errorf("no matching fields in struct %T, from %v", *x, dec.Type())
- }
return dec.FinishValue()
case "Desc":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -174,7 +169,6 @@
return err
}
case "SgPublishSb":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -285,7 +279,6 @@
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
}
- match := 0
for {
f, err := dec.NextField()
if err != nil {
@@ -293,12 +286,8 @@
}
switch f {
case "":
- if match == 0 && dec.Type().NumField() > 0 {
- return fmt.Errorf("no matching fields in struct %T, from %v", *x, dec.Type())
- }
return dec.FinishValue()
case "DevId":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -493,7 +482,6 @@
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
}
- match := 0
for {
f, err := dec.NextField()
if err != nil {
@@ -501,12 +489,8 @@
}
switch f {
case "":
- if match == 0 && dec.Type().NumField() > 0 {
- return fmt.Errorf("no matching fields in struct %T, from %v", *x, dec.Type())
- }
return dec.FinishValue()
case "Script":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -517,7 +501,6 @@
return err
}
case "Start":
- match++
var wire time_2.Time
if err = wire.VDLRead(dec); err != nil {
return err
@@ -526,7 +509,6 @@
return err
}
case "Interval":
- match++
var wire time_2.Duration
if err = wire.VDLRead(dec); err != nil {
return err
@@ -697,7 +679,6 @@
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
}
- match := 0
for {
f, err := dec.NextField()
if err != nil {
@@ -705,12 +686,8 @@
}
switch f {
case "":
- if match == 0 && dec.Type().NumField() > 0 {
- return fmt.Errorf("no matching fields in struct %T, from %v", *x, dec.Type())
- }
return dec.FinishValue()
case "Desc":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -721,12 +698,10 @@
return err
}
case "Sampler":
- match++
if err = x.Sampler.VDLRead(dec); err != nil {
return err
}
case "Enabled":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -865,7 +840,6 @@
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
}
- match := 0
for {
f, err := dec.NextField()
if err != nil {
@@ -873,12 +847,8 @@
}
switch f {
case "":
- if match == 0 && dec.Type().NumField() > 0 {
- return fmt.Errorf("no matching fields in struct %T, from %v", *x, dec.Type())
- }
return dec.FinishValue()
case "DevId":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -889,7 +859,6 @@
return err
}
case "StreamId":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -1070,7 +1039,6 @@
if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
}
- match := 0
for {
f, err := dec.NextField()
if err != nil {
@@ -1078,12 +1046,8 @@
}
switch f {
case "":
- if match == 0 && dec.Type().NumField() > 0 {
- return fmt.Errorf("no matching fields in struct %T, from %v", *x, dec.Type())
- }
return dec.FinishValue()
case "DevId":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -1094,7 +1058,6 @@
return err
}
case "StreamId":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -1105,7 +1068,6 @@
return err
}
case "Timestamp":
- match++
var wire time_2.Time
if err = wire.VDLRead(dec); err != nil {
return err