data tree CHANGE do not allow changing order of several instances
Because it became confusing if only moving
instances within one list and the feature
is useless, anyway.
diff --git a/src/tree_data.c b/src/tree_data.c
index 9a42270..68ed9bf 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -2066,8 +2066,6 @@
API LY_ERR
lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node)
{
- struct lyd_node *iter;
-
LY_CHECK_ARG_RET(NULL, sibling, node, LY_EINVAL);
LY_CHECK_RET(lyd_insert_check_schema(NULL, sibling->schema, node->schema));
@@ -2077,32 +2075,16 @@
return LY_EINVAL;
}
- if (node->parent || node->prev->next) {
- lyd_unlink_tree(node);
- }
+ lyd_unlink_tree(node);
+ lyd_insert_before_node(sibling, node);
+ lyd_insert_hash(node);
- /* insert in reverse order to get the original order */
- node = node->prev;
- while (node) {
- iter = node->prev;
- lyd_unlink_tree(node);
-
- lyd_insert_before_node(sibling, node);
- lyd_insert_hash(node);
-
- /* move the anchor accordingly */
- sibling = node;
-
- node = (iter == node) ? NULL : iter;
- }
return LY_SUCCESS;
}
API LY_ERR
lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node)
{
- struct lyd_node *iter;
-
LY_CHECK_ARG_RET(NULL, sibling, node, LY_EINVAL);
LY_CHECK_RET(lyd_insert_check_schema(NULL, sibling->schema, node->schema));
@@ -2112,22 +2094,10 @@
return LY_EINVAL;
}
- if (node->parent || node->prev->next) {
- lyd_unlink_tree(node);
- }
+ lyd_unlink_tree(node);
+ lyd_insert_after_node(sibling, node);
+ lyd_insert_hash(node);
- while (node) {
- iter = node->next;
- lyd_unlink_tree(node);
-
- lyd_insert_after_node(sibling, node);
- lyd_insert_hash(node);
-
- /* move the anchor accordingly */
- sibling = node;
-
- node = iter;
- }
return LY_SUCCESS;
}
diff --git a/src/tree_data.h b/src/tree_data.h
index f93d42f..fd8a569 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -1153,9 +1153,9 @@
/**
* @brief Insert a node before another node, can be used only for user-ordered nodes.
+ * If inserting several siblings, each of them must be inserted individually.
*
* - if the node is part of some other tree, it is automatically unlinked.
- * - if the node is the first node of a node list (with no parent), all the subsequent nodes are also inserted.
*
* @param[in] sibling Sibling node to insert before.
* @param[in] node Node to insert.
@@ -1166,9 +1166,9 @@
/**
* @brief Insert a node after another node, can be used only for user-ordered nodes.
+ * If inserting several siblings, each of them must be inserted individually.
*
* - if the node is part of some other tree, it is automatically unlinked.
- * - if the node is the first node of a node list (with no parent), all the subsequent nodes are also inserted.
*
* @param[in] sibling Sibling node to insert after.
* @param[in] node Node to insert.