* 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. */
| 3602 | * when we are sure the node is not already in the set. |
| 3603 | */ |
| 3604 | void |
| 3605 | xmlXPathNodeSetAddUnique(xmlNodeSetPtr cur, xmlNodePtr val) { |
| 3606 | if ((cur == NULL) || (val == NULL)) return; |
| 3607 | |
| 3608 | #if 0 |
| 3609 | if ((val->type == XML_ELEMENT_NODE) && (val->name[0] == ' ')) |
| 3610 | return; /* an XSLT fake node */ |
| 3611 | #endif |
| 3612 | |
| 3613 | /* @@ with_ns to check whether namespace nodes should be looked at @@ */ |
| 3614 | /* |
| 3615 | * grow the nodeTab if needed |
| 3616 | */ |
| 3617 | if (cur->nodeMax == 0) { |
| 3618 | cur->nodeTab = (xmlNodePtr *) xmlMalloc(XML_NODESET_DEFAULT * |
| 3619 | sizeof(xmlNodePtr)); |
| 3620 | if (cur->nodeTab == NULL) { |
| 3621 | xmlXPathErrMemory(NULL, "growing nodeset\n"); |
| 3622 | return; |
| 3623 | } |
| 3624 | memset(cur->nodeTab, 0 , |
| 3625 | XML_NODESET_DEFAULT * (size_t) sizeof(xmlNodePtr)); |
| 3626 | cur->nodeMax = XML_NODESET_DEFAULT; |
| 3627 | } else if (cur->nodeNr == cur->nodeMax) { |
| 3628 | xmlNodePtr *temp; |
| 3629 | |
| 3630 | cur->nodeMax *= 2; |
| 3631 | temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * |
| 3632 | sizeof(xmlNodePtr)); |
| 3633 | if (temp == NULL) { |
| 3634 | xmlXPathErrMemory(NULL, "growing nodeset\n"); |
| 3635 | return; |
| 3636 | } |
| 3637 | cur->nodeTab = temp; |
| 3638 | } |
| 3639 | if (val->type == XML_NAMESPACE_DECL) { |
| 3640 | xmlNsPtr ns = (xmlNsPtr) val; |
| 3641 | |
| 3642 | cur->nodeTab[cur->nodeNr++] = |
| 3643 | xmlXPathNodeSetDupNs((xmlNodePtr) ns->next, ns); |
| 3644 | } else |
| 3645 | cur->nodeTab[cur->nodeNr++] = val; |
| 3646 | } |
| 3647 | |
| 3648 | /** |
| 3649 | * xmlXPathNodeSetMerge: |