[libcxx-commits] [libcxx] [libc++] Remove unnecessary static_casts in std::forward_list (PR #130310)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Mar 8 10:38:30 PST 2025
================
@@ -296,7 +296,7 @@ struct __forward_node_traits {
# endif
_LIBCPP_HIDE_FROM_ABI static __begin_node_pointer __as_iter_node(__node_pointer __p) {
- return static_cast<__begin_node_pointer>(static_cast<__void_pointer>(__p));
+ return static_cast<__begin_node_pointer>(__p);
}
----------------
winner245 wrote:
Yeah, I agree that inlining these short one-liner `static_cast`s makes sense—it doesn’t bloat the code and actually improves readability. For instance, after getting rid of the unnecessary casts, `__get_begin()` is nothing but a class getter, and inlining `_iter.__get_begin()` as `__iter.__ptr_` makes the code more obvious. So I've inlined all three functions. Additionally, I noticed that `__p->__next_as_begin()` exactly duplicates the functionality of `__as_iter_node(__p->__next_)`, so I think we can get rid of the function `__next_as_begin()` entirely. Then we can inline the calls to `__next_as_begin()` as well (if we choose not to inline `__as_iter_node`, we can simply replace the `__next_as_begin` calls by`__as_iter_node`). I'm not sure if I am doing too much of inlining here (please let me know if you dislike some of the inlining).
https://github.com/llvm/llvm-project/pull/130310
More information about the libcxx-commits
mailing list