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: 2/4
Change-Id: Id161477cc6812edc5a2b6895bc0ec95fd4280781
diff --git a/test/fortune/fortune.vdl.go b/test/fortune/fortune.vdl.go
index 87c5051..404f6fc 100644
--- a/test/fortune/fortune.vdl.go
+++ b/test/fortune/fortune.vdl.go
@@ -226,7 +226,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 {
@@ -234,12 +233,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 "Str":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -250,7 +245,6 @@
return err
}
case "Num":
- match++
if err = dec.StartValue(); err != nil {
return err
}
@@ -263,7 +257,6 @@
return err
}
case "List":
- match++
if err = __VDLRead1_list(dec, &x.List); err != nil {
return err
}
@@ -284,10 +277,10 @@
return fmt.Errorf("incompatible list %T, from %v", *x, dec.Type())
}
switch len := dec.LenHint(); {
- case len == 0:
- *x = nil
case len > 0:
*x = make([]uint32, 0, len)
+ default:
+ *x = nil
}
for {
switch done, err := dec.NextEntry(); {