Optimization of yang_find()
This commit is contained in:
parent
d76adf51d2
commit
012158fb24
4 changed files with 25 additions and 29 deletions
|
|
@ -83,9 +83,9 @@
|
||||||
* leaf z;
|
* leaf z;
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
#define YANG_FLAG_MOUNTPOINT 0x100 /* Mark node as populated mount-point
|
#define YANG_FLAG_MOUNTPOINT 0x100 /* Mark node as ACTUAL populated mount-point
|
||||||
* Set by yang_mount_set.
|
* Set by yang_mount_set
|
||||||
* Used by ys_free
|
* Read by ys_free1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -948,13 +948,11 @@ xmldb_get_cache(clicon_handle h,
|
||||||
} /* x0t == NULL */
|
} /* x0t == NULL */
|
||||||
else
|
else
|
||||||
x0t = de->de_xml;
|
x0t = de->de_xml;
|
||||||
|
|
||||||
if (yb == YB_MODULE && !xml_spec(x0t)){
|
if (yb == YB_MODULE && !xml_spec(x0t)){
|
||||||
|
/* Seems unneccesary to always do this, but breaks test_plugin_reset.sh if removed */
|
||||||
if ((ret = xml_bind_yang(h, x0t, YB_MODULE, yspec, xerr)) < 0)
|
if ((ret = xml_bind_yang(h, x0t, YB_MODULE, yspec, xerr)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 0)
|
if (ret == 1) {
|
||||||
; /* XXX */
|
|
||||||
else {
|
|
||||||
/* Add default global values (to make xpath below include defaults) */
|
/* Add default global values (to make xpath below include defaults) */
|
||||||
if (xml_global_defaults(h, x0t, nsc, xpath, yspec, 0) < 0)
|
if (xml_global_defaults(h, x0t, nsc, xpath, yspec, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
|
|
@ -1108,12 +1108,14 @@ yn_each(yang_stmt *yparent,
|
||||||
|
|
||||||
/*! Find first child yang_stmt with matching keyword and argument
|
/*! Find first child yang_stmt with matching keyword and argument
|
||||||
*
|
*
|
||||||
|
* Find child given keyword and argument.
|
||||||
|
* Special case: look in imported INPUTs as well (for (sub)modules.
|
||||||
|
* This could need an optimized lookup, especially the INPUT case.
|
||||||
|
* Most common use for the special case, ie in openconfig, is grouping and identity
|
||||||
* @param[in] yn Yang node, current context node.
|
* @param[in] yn Yang node, current context node.
|
||||||
* @param[in] keyword if 0 match any keyword. Actual type: enum rfc_6020
|
* @param[in] keyword if 0 match any keyword. Actual type: enum rfc_6020
|
||||||
* @param[in] argument String compare w argument. if NULL, match any.
|
* @param[in] argument String compare w argument. if NULL, match any.
|
||||||
* @retval ys Yang statement, if any
|
* @retval ys Yang statement, if any
|
||||||
* This however means that if you actually want to match only a yang-stmt with
|
|
||||||
* argument==NULL you cannot, but I have not seen any such examples.
|
|
||||||
* @see yang_find_datanode
|
* @see yang_find_datanode
|
||||||
* @see yang_match returns number of matches
|
* @see yang_match returns number of matches
|
||||||
*/
|
*/
|
||||||
|
|
@ -1125,6 +1127,7 @@ yang_find(yang_stmt *yn,
|
||||||
yang_stmt *ys = NULL;
|
yang_stmt *ys = NULL;
|
||||||
int i;
|
int i;
|
||||||
yang_stmt *yret = NULL;
|
yang_stmt *yret = NULL;
|
||||||
|
yang_stmt *yretsub = NULL;
|
||||||
char *name;
|
char *name;
|
||||||
yang_stmt *yspec;
|
yang_stmt *yspec;
|
||||||
yang_stmt *ym;
|
yang_stmt *ym;
|
||||||
|
|
@ -1138,24 +1141,22 @@ yang_find(yang_stmt *yn,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
/* Special case: if not match and yang node is module or submodule, extend
|
||||||
/* Special case: if not match and yang node is module or submodule, extend
|
* search to include submodules
|
||||||
* search to include submodules */
|
*/
|
||||||
if (yret == NULL &&
|
if (yretsub == NULL &&
|
||||||
(yang_keyword_get(yn) == Y_MODULE ||
|
yang_keyword_get(ys) == Y_INCLUDE &&
|
||||||
yang_keyword_get(yn) == Y_SUBMODULE)){
|
keyword != Y_NAMESPACE &&
|
||||||
yspec = ys_spec(yn);
|
(yang_keyword_get(yn) == Y_MODULE ||
|
||||||
for (i=0; i<yn->ys_len; i++){
|
yang_keyword_get(yn) == Y_SUBMODULE)){
|
||||||
ys = yn->ys_stmt[i];
|
yspec = ys_spec(yn);
|
||||||
if (yang_keyword_get(ys) == Y_INCLUDE){
|
name = yang_argument_get(ys);
|
||||||
name = yang_argument_get(ys);
|
if ((ym = yang_find_module_by_name(yspec, name)) != NULL) {
|
||||||
if ((ym = yang_find_module_by_name(yspec, name)) != NULL &&
|
yretsub = yang_find(ym, keyword, argument);
|
||||||
(yret = yang_find(ym, keyword, argument)) != NULL)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return yret;
|
return yret?yret:yretsub;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Count number of children that matches keyword and argument
|
/*! Count number of children that matches keyword and argument
|
||||||
|
|
@ -3863,7 +3864,6 @@ yang_anydata_add(yang_stmt *yp,
|
||||||
* }
|
* }
|
||||||
* @endcode
|
* @endcode
|
||||||
* @see ys_populate_unknown Called when parsing YANG
|
* @see ys_populate_unknown Called when parsing YANG
|
||||||
* XXX consider optimizing, the call to yang_find_prefix_by_namespace may be slow
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
yang_extension_value(yang_stmt *ys,
|
yang_extension_value(yang_stmt *ys,
|
||||||
|
|
@ -3896,7 +3896,6 @@ yang_extension_value(yang_stmt *ys,
|
||||||
continue;
|
continue;
|
||||||
if ((ymod = ys_module(yext)) == NULL)
|
if ((ymod = ys_module(yext)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
/* XXX this is slow */
|
|
||||||
if ((ret = yang_find_prefix_by_namespace(ymod, ns, &prefix)) < 0)
|
if ((ret = yang_find_prefix_by_namespace(ymod, ns, &prefix)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (ret == 0) /* not found (this may happen in augment and maybe should be treated otherwise) */
|
if (ret == 0) /* not found (this may happen in augment and maybe should be treated otherwise) */
|
||||||
|
|
|
||||||
|
|
@ -113,4 +113,3 @@ struct yang_stmt{
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _CLIXON_YANG_INTERNAL_H_ */
|
#endif /* _CLIXON_YANG_INTERNAL_H_ */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue