performance: reduce the number of fills

- Remove unnecessary Fill() in Export()
- Change `set()` and the way we store outputs so we don't fill
  intermediaries as much
- WIP: Scan the tree only once. Changed LocalDirs to use cueflow rather than
  doing our own Walk. In a follow up we should use the same flow
  instance.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-02-19 14:04:40 -08:00
parent d5830fbaca
commit 890fdb4176
6 changed files with 86 additions and 103 deletions

View File

@@ -17,7 +17,7 @@ func Compile(name string, src interface{}) (*Value, error) {
return DefaultCompiler.Compile(name, src)
}
func EmptyStruct() (*Value, error) {
func EmptyStruct() *Value {
return DefaultCompiler.EmptyStruct()
}
@@ -63,8 +63,12 @@ func (c *Compiler) Cue() *cue.Runtime {
}
// Compile an empty struct
func (c *Compiler) EmptyStruct() (*Value, error) {
return c.Compile("", "")
func (c *Compiler) EmptyStruct() *Value {
empty, err := c.Compile("", "")
if err != nil {
panic(err)
}
return empty
}
func (c *Compiler) Compile(name string, src interface{}) (*Value, error) {

View File

@@ -38,14 +38,6 @@ func TestDefNotExist(t *testing.T) {
}
}
func TestSimple(t *testing.T) {
c := &Compiler{}
_, err := c.EmptyStruct()
if err != nil {
t.Fatal(err)
}
}
func TestJSON(t *testing.T) {
c := &Compiler{}
v, err := c.Compile("", `foo: hello: "world"`)

View File

@@ -67,6 +67,11 @@ func (v *Value) Len() cue.Value {
return v.val.Len()
}
// Proxy function to the underlying cue.Value
func (v *Value) Kind() cue.Kind {
return v.val.Kind()
}
// Proxy function to the underlying cue.Value
func (v *Value) Fields() (*cue.Iterator, error) {
return v.val.Fields()