Skip to content
Permalink
Browse files

Optimise nil checking in rendering structs to Notifications. (#302)

* (M) ygot/render.go
  - Before this change, we calculate the paths that a field should be
    mapped to before we check whether it is nil or not, we can avoid
    doing any check of a struct field's path at all if we check whether
    it was nil *before*.
  • Loading branch information...
robshakir committed Aug 3, 2019
1 parent 724a6b1 commit 66c5ff6a5d1980caa774cb7321e99a4734731787
Showing with 6 additions and 6 deletions.
  1. +6 −6 ygot/render.go
@@ -323,12 +323,6 @@ func findUpdatedLeaves(leaves map[*path]interface{}, s GoStruct, parent *gnmiPat
fval := sval.Field(i)
ftype := stype.Field(i)

mapPaths, err := structTagToLibPaths(ftype, parent)
if err != nil {
errs.Add(fmt.Errorf("%v->%s: %v", parent, ftype.Name, err))
continue
}

// Handle nil values, and enumerations specifically.
switch fval.Kind() {
case reflect.Map, reflect.Slice, reflect.Ptr, reflect.Interface:
@@ -337,6 +331,12 @@ func findUpdatedLeaves(leaves map[*path]interface{}, s GoStruct, parent *gnmiPat
}
}

mapPaths, err := structTagToLibPaths(ftype, parent)
if err != nil {
errs.Add(fmt.Errorf("%v->%s: %v", parent, ftype.Name, err))
continue
}

switch fval.Kind() {
case reflect.Map:
// We need to map each child along with its key value.

0 comments on commit 66c5ff6

Please sign in to comment.
You can’t perform that action at this time.