Skip to content

Commit

Permalink
XXX cache map inputs
Browse files Browse the repository at this point in the history
Is this correct? Is looking at the length along sufficient?
  • Loading branch information
purpleidea committed Aug 4, 2023
1 parent 7d30bf1 commit f6280ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lang/fancyfunc/fancy_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ func (obj *FuncValue) Cmp(val types.Value) error {
return errwrap.Wrapf(err, "cannot cmp types")
}

return fmt.Errorf("cannot cmp funcs") // TODO: can we ?
if obj != val { // best we can do
return fmt.Errorf("different pointers")
}

return nil
}

// Copy returns a copy of this value.
Expand Down
7 changes: 7 additions & 0 deletions lang/funcs/core/iter/map_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type MapFunc struct {
RType *types.Type // this is the type of the elements in our output list

init *interfaces.Init
last types.Value // last value received to use for diff

lastFuncValue *fancyfunc.FuncValue // remember the last function value
lastInputListLength int // remember the last input list length
Expand Down Expand Up @@ -627,6 +628,12 @@ func (obj *MapFunc) Stream(ctx context.Context) error {
continue
}

// XXX: double check this passes through function changes
if obj.last != nil && input.Cmp(obj.last) == nil {
continue // value didn't change, skip it
}
obj.last = input // store for next

value, exists := input.Struct()[mapArgNameFunction]
if !exists {
return fmt.Errorf("programming error, can't find edge")
Expand Down

0 comments on commit f6280ef

Please sign in to comment.