[libcxx-commits] [libcxx] [libc++] Improve performance of std::midpoint for small types (PR #192804)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Apr 18 11:10:42 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h -- libcxx/include/__numeric/midpoint.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/include/__numeric/midpoint.h b/libcxx/include/__numeric/midpoint.h
index 7c3f8cc8b..736e2b152 100644
--- a/libcxx/include/__numeric/midpoint.h
+++ b/libcxx/include/__numeric/midpoint.h
@@ -36,10 +36,9 @@ template <class _Tp>
 [[nodiscard]]
 _LIBCPP_HIDE_FROM_ABI constexpr _Tp midpoint(_Tp __a, _Tp __b) noexcept _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK {
   using _Up                = make_unsigned_t<_Tp>;
-  if constexpr(sizeof(_Tp) < sizeof(unsigned)) {
+  if constexpr (sizeof(_Tp) < sizeof(unsigned)) {
     return (static_cast<unsigned>(__a) + static_cast<unsigned>(__b)) / 2;
-  }
-  else {
+  } else {
     constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1;
 
     _Up __diff     = _Up(__b) - _Up(__a);

``````````

</details>


https://github.com/llvm/llvm-project/pull/192804


More information about the libcxx-commits mailing list