[libcxx-commits] [libcxx] 485b908 - [libc++] Mark __u64toa and __u32toa as noexcept
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 22 13:12:02 PDT 2020
Author: Louis Dionne
Date: 2020-05-22T16:11:44-04:00
New Revision: 485b9083fe69601c9f3f91f7f1be9d7f3a26bb1e
URL: https://github.com/llvm/llvm-project/commit/485b9083fe69601c9f3f91f7f1be9d7f3a26bb1e
DIFF: https://github.com/llvm/llvm-project/commit/485b9083fe69601c9f3f91f7f1be9d7f3a26bb1e.diff
LOG: [libc++] Mark __u64toa and __u32toa as noexcept
The two functions don't throw, and the generated code is better when
we explicitly tell the compiler that the functions are noexcept. This
isn't an ABI break because the signatures of the functions stay the
same with or without noexcept.
Fixes https://llvm.org/PR46016
Differential Revision: https://reviews.llvm.org/D80379
Added:
Modified:
libcxx/include/charconv
libcxx/src/charconv.cpp
Removed:
################################################################################
diff --git a/libcxx/include/charconv b/libcxx/include/charconv
index 55809b92f217..b64000242a7e 100644
--- a/libcxx/include/charconv
+++ b/libcxx/include/charconv
@@ -93,8 +93,8 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
namespace __itoa {
-_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer);
-_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer);
+_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer) _NOEXCEPT;
+_LIBCPP_AVAILABILITY_TO_CHARS _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer) _NOEXCEPT;
}
#ifndef _LIBCPP_CXX03_LANG
diff --git a/libcxx/src/charconv.cpp b/libcxx/src/charconv.cpp
index d3035883a78f..8cfe40d156b2 100644
--- a/libcxx/src/charconv.cpp
+++ b/libcxx/src/charconv.cpp
@@ -32,7 +32,7 @@ static constexpr char cDigitsLut[200] = {
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
-append1(char* buffer, T i)
+append1(char* buffer, T i) noexcept
{
*buffer = '0' + static_cast<char>(i);
return buffer + 1;
@@ -40,7 +40,7 @@ append1(char* buffer, T i)
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
-append2(char* buffer, T i)
+append2(char* buffer, T i) noexcept
{
memcpy(buffer, &cDigitsLut[(i)*2], 2);
return buffer + 2;
@@ -48,21 +48,21 @@ append2(char* buffer, T i)
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
-append3(char* buffer, T i)
+append3(char* buffer, T i) noexcept
{
return append2(append1(buffer, (i) / 100), (i) % 100);
}
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
-append4(char* buffer, T i)
+append4(char* buffer, T i) noexcept
{
return append2(append2(buffer, (i) / 100), (i) % 100);
}
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
-append2_no_zeros(char* buffer, T v)
+append2_no_zeros(char* buffer, T v) noexcept
{
if (v < 10)
return append1(buffer, v);
@@ -72,7 +72,7 @@ append2_no_zeros(char* buffer, T v)
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
-append4_no_zeros(char* buffer, T v)
+append4_no_zeros(char* buffer, T v) noexcept
{
if (v < 100)
return append2_no_zeros(buffer, v);
@@ -84,7 +84,7 @@ append4_no_zeros(char* buffer, T v)
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
-append8_no_zeros(char* buffer, T v)
+append8_no_zeros(char* buffer, T v) noexcept
{
if (v < 10000)
{
@@ -99,7 +99,7 @@ append8_no_zeros(char* buffer, T v)
}
char*
-__u32toa(uint32_t value, char* buffer)
+__u32toa(uint32_t value, char* buffer) _NOEXCEPT
{
if (value < 100000000)
{
@@ -120,7 +120,7 @@ __u32toa(uint32_t value, char* buffer)
}
char*
-__u64toa(uint64_t value, char* buffer)
+__u64toa(uint64_t value, char* buffer) _NOEXCEPT
{
if (value < 100000000)
{
More information about the libcxx-commits
mailing list