MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlXPathNodeSetAddUnique

Function xmlXPathNodeSetAddUnique

ThirdParty/libxml2/vtklibxml2/xpath.c:2967–3005  ·  view source on GitHub ↗

* xmlXPathNodeSetAddUnique: * @cur: the initial node set * @val: a new xmlNodePtr * * add a new xmlNodePtr to an existing NodeSet, optimized version * when we are sure the node is not already in the set. * * Returns 0 in case of success and -1 in case of failure */

Source from the content-addressed store, hash-verified

2965 * Returns 0 in case of success and -1 in case of failure
2966 */
2967int
2968xmlXPathNodeSetAddUnique(xmlNodeSetPtr cur, xmlNodePtr val) {
2969 if ((cur == NULL) || (val == NULL)) return(-1);
2970
2971 /* @@ with_ns to check whether namespace nodes should be looked at @@ */
2972 /*
2973 * grow the nodeTab if needed
2974 */
2975 if (cur->nodeMax == 0) {
2976 cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT *
2977 sizeof(xmlNodePtr));
2978 if (cur->nodeTab == NULL)
2979 return(-1);
2980 memset(cur->nodeTab, 0 ,
2981 XML_NODESET_DEFAULT * sizeof(xmlNodePtr));
2982 cur->nodeMax = XML_NODESET_DEFAULT;
2983 } else if (cur->nodeNr == cur->nodeMax) {
2984 xmlNodePtr *temp;
2985
2986 if (cur->nodeMax >= XPATH_MAX_NODESET_LENGTH)
2987 return(-1);
2988 temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 *
2989 sizeof(xmlNodePtr));
2990 if (temp == NULL)
2991 return(-1);
2992 cur->nodeTab = temp;
2993 cur->nodeMax *= 2;
2994 }
2995 if (val->type == XML_NAMESPACE_DECL) {
2996 xmlNsPtr ns = (xmlNsPtr) val;
2997 xmlNodePtr nsNode = xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns);
2998
2999 if (nsNode == NULL)
3000 return(-1);
3001 cur->nodeTab[cur->nodeNr++] = nsNode;
3002 } else
3003 cur->nodeTab[cur->nodeNr++] = val;
3004 return(0);
3005}
3006
3007/**
3008 * xmlXPathNodeSetMerge:

Callers 7

xmlXPathCacheNewNodeSetFunction · 0.85
xmlXPathDifferenceFunction · 0.85
xmlXPathIntersectionFunction · 0.85
xmlXPathDistinctSortedFunction · 0.85
xmlXPathRunStreamEvalFunction · 0.85

Calls 1

xmlXPathNodeSetDupNsFunction · 0.85

Tested by

no test coverage detected