Skip to content

[libc++] Set the child pointer outside __insert_node_at in __tree #152685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

philnik777
Copy link
Contributor

This avoids an out parameter in __insert_node_at and makes it more obivious what is actually going on.

Copy link

github-actions bot commented Aug 8, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions  -- libcxx/include/__tree libcxx/include/map
View the diff from clang-format here.
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index d526ecc8e..bdad62483 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -1781,7 +1781,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
   bool __inserted              = false;
   if (__child == nullptr) {
     __node_holder __h = __construct_node(std::forward<_Args>(__args)...);
-    __child = static_cast<__node_base_pointer>(__h.get());
+    __child           = static_cast<__node_base_pointer>(__h.get());
     __insert_node_at(__parent, __child);
     __r        = __h.release();
     __inserted = true;
@@ -1854,7 +1854,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, _Arg
   __node_holder __h = __construct_node(std::forward<_Args>(__args)...);
   __end_node_pointer __parent;
   __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_);
-  __child = static_cast<__node_base_pointer>(__h.get());
+  __child                      = static_cast<__node_base_pointer>(__h.get());
   __insert_node_at(__parent, __child);
   return iterator(static_cast<__node_pointer>(__h.release()));
 }
diff --git a/libcxx/include/map b/libcxx/include/map
index 60ed4ea0b..c9db5e996 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -1433,7 +1433,7 @@ _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
   __node_pointer __r           = static_cast<__node_pointer>(__child);
   if (__child == nullptr) {
     __node_holder __h = __construct_node_with_key(__k);
-    __child = static_cast<__node_base_pointer>(__h.get());
+    __child           = static_cast<__node_base_pointer>(__h.get());
     __tree_.__insert_node_at(__parent, __child);
     __r = __h.release();
   }

@philnik777 philnik777 force-pushed the tree_refactor_insert_node_at branch from 8c206a1 to b74ca2e Compare August 11, 2025 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant