diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:33 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-08-02 17:33:33 +0000 |
| commit | 315d10f09ee888005b1da55e7bbb57d8a79b8447 (patch) | |
| tree | 99a16e8c2272e507281e63fac5970e0548df04ea /src | |
| parent | f36202620b428c45a1c8d91743727c9313424fb2 (diff) | |
Notes
Diffstat (limited to 'src')
| -rw-r--r-- | src/bind.cpp | 1 | ||||
| -rw-r--r-- | src/charconv.cpp | 233 | ||||
| -rw-r--r-- | src/future.cpp | 44 | ||||
| -rw-r--r-- | src/memory.cpp | 1 | ||||
| -rw-r--r-- | src/mutex.cpp | 1 | ||||
| -rw-r--r-- | src/new.cpp | 2 | ||||
| -rw-r--r-- | src/shared_mutex.cpp | 1 | ||||
| -rw-r--r-- | src/system_error.cpp | 1 | ||||
| -rw-r--r-- | src/utility.cpp | 1 |
9 files changed, 244 insertions, 41 deletions
diff --git a/src/bind.cpp b/src/bind.cpp index b318fc16979ec..b4c76ffe6a4da 100644 --- a/src/bind.cpp +++ b/src/bind.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// -#define _LIBCPP_BUILDING_BIND #include "functional" _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/src/charconv.cpp b/src/charconv.cpp new file mode 100644 index 0000000000000..ec241db744713 --- /dev/null +++ b/src/charconv.cpp @@ -0,0 +1,233 @@ +//===------------------------- charconv.cpp -------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "charconv" +#include <string.h> + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace __itoa +{ + +static constexpr char cDigitsLut[200] = { + '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', + '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', + '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2', + '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', + '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', + '7', '3', '8', '3', '9', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', + '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0', '5', '1', '5', + '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', + '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', + '7', '6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', + '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8', + '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', + '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', + '7', '9', '8', '9', '9'}; + +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append1(char* buffer, T i) +{ + *buffer = '0' + static_cast<char>(i); + return buffer + 1; +} + +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append2(char* buffer, T i) +{ + memcpy(buffer, &cDigitsLut[(i)*2], 2); + return buffer + 2; +} + +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append3(char* buffer, T i) +{ + return append2(append1(buffer, (i) / 100), (i) % 100); +} + +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append4(char* buffer, T i) +{ + return append2(append2(buffer, (i) / 100), (i) % 100); +} + +char* +__u32toa(uint32_t value, char* buffer) +{ + if (value < 10000) + { + if (value < 100) + { + if (value < 10) + buffer = append1(buffer, value); + else + buffer = append2(buffer, value); + } + else + { + if (value < 1000) + buffer = append3(buffer, value); + else + buffer = append4(buffer, value); + } + } + else if (value < 100000000) + { + // value = bbbbcccc + const uint32_t b = value / 10000; + const uint32_t c = value % 10000; + + if (value < 1000000) + { + if (value < 100000) + buffer = append1(buffer, b); + else + buffer = append2(buffer, b); + } + else + { + if (value < 10000000) + buffer = append3(buffer, b); + else + buffer = append4(buffer, b); + } + + buffer = append4(buffer, c); + } + else + { + // value = aabbbbcccc in decimal + const uint32_t a = value / 100000000; // 1 to 42 + value %= 100000000; + + if (a < 10) + buffer = append1(buffer, a); + else + buffer = append2(buffer, a); + + buffer = append4(buffer, value / 10000); + buffer = append4(buffer, value % 10000); + } + + return buffer; +} + +char* +__u64toa(uint64_t value, char* buffer) +{ + if (value < 100000000) + { + uint32_t v = static_cast<uint32_t>(value); + if (v < 10000) + { + if (v < 100) + { + if (v < 10) + buffer = append1(buffer, v); + else + buffer = append2(buffer, v); + } + else + { + if (v < 1000) + buffer = append3(buffer, v); + else + buffer = append4(buffer, v); + } + } + else + { + // value = bbbbcccc + const uint32_t b = v / 10000; + const uint32_t c = v % 10000; + + if (v < 1000000) + { + if (v < 100000) + buffer = append1(buffer, b); + else + buffer = append2(buffer, b); + } + else + { + if (v < 10000000) + buffer = append3(buffer, b); + else + buffer = append4(buffer, b); + } + + buffer = append4(buffer, c); + } + } + else if (value < 10000000000000000) + { + const uint32_t v0 = static_cast<uint32_t>(value / 100000000); + const uint32_t v1 = static_cast<uint32_t>(value % 100000000); + + const uint32_t b0 = v0 / 10000; + const uint32_t c0 = v0 % 10000; + + if (v0 < 1000000) + { + if (v0 < 100000) + buffer = append1(buffer, b0); + else + buffer = append2(buffer, b0); + } + else + { + if (v0 < 10000000) + buffer = append3(buffer, b0); + else + buffer = append4(buffer, b0); + } + + buffer = append4(buffer, c0); + buffer = append4(buffer, v1 / 10000); + buffer = append4(buffer, v1 % 10000); + } + else + { + const uint32_t a = + static_cast<uint32_t>(value / 10000000000000000); // 1 to 1844 + value %= 10000000000000000; + + if (a < 100) + { + if (a < 10) + buffer = append1(buffer, a); + else + buffer = append2(buffer, a); + } + else + { + if (a < 1000) + buffer = append3(buffer, a); + else + buffer = append4(buffer, a); + } + + const uint32_t v0 = static_cast<uint32_t>(value / 100000000); + const uint32_t v1 = static_cast<uint32_t>(value % 100000000); + buffer = append4(buffer, v0 / 10000); + buffer = append4(buffer, v0 % 10000); + buffer = append4(buffer, v1 / 10000); + buffer = append4(buffer, v1 % 10000); + } + + return buffer; +} + +} // namespace __itoa + +_LIBCPP_END_NAMESPACE_STD diff --git a/src/future.cpp b/src/future.cpp index e1758f39df3a7..07e4602f567ff 100644 --- a/src/future.cpp +++ b/src/future.cpp @@ -92,10 +92,8 @@ void __assoc_sub_state::set_value() { unique_lock<mutex> __lk(__mut_); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__has_value()) - throw future_error(make_error_code(future_errc::promise_already_satisfied)); -#endif + __throw_future_error(future_errc::promise_already_satisfied); __state_ |= __constructed | ready; __cv_.notify_all(); } @@ -104,10 +102,8 @@ void __assoc_sub_state::set_value_at_thread_exit() { unique_lock<mutex> __lk(__mut_); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__has_value()) - throw future_error(make_error_code(future_errc::promise_already_satisfied)); -#endif + __throw_future_error(future_errc::promise_already_satisfied); __state_ |= __constructed; __thread_local_data()->__make_ready_at_thread_exit(this); } @@ -116,10 +112,8 @@ void __assoc_sub_state::set_exception(exception_ptr __p) { unique_lock<mutex> __lk(__mut_); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__has_value()) - throw future_error(make_error_code(future_errc::promise_already_satisfied)); -#endif + __throw_future_error(future_errc::promise_already_satisfied); __exception_ = __p; __state_ |= ready; __cv_.notify_all(); @@ -129,10 +123,8 @@ void __assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p) { unique_lock<mutex> __lk(__mut_); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__has_value()) - throw future_error(make_error_code(future_errc::promise_already_satisfied)); -#endif + __throw_future_error(future_errc::promise_already_satisfied); __exception_ = __p; __thread_local_data()->__make_ready_at_thread_exit(this); } @@ -181,18 +173,14 @@ __assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk) void __assoc_sub_state::__execute() { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw future_error(make_error_code(future_errc::no_state)); -#endif + __throw_future_error(future_errc::no_state); } future<void>::future(__assoc_sub_state* __state) : __state_(__state) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_->__has_future_attached()) - throw future_error(make_error_code(future_errc::future_already_retrieved)); -#endif + __throw_future_error(future_errc::future_already_retrieved); __state_->__add_shared(); __state_->__set_future_attached(); } @@ -234,50 +222,40 @@ promise<void>::~promise() future<void> promise<void>::get_future() { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __throw_future_error(future_errc::no_state); return future<void>(__state_); } void promise<void>::set_value() { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __throw_future_error(future_errc::no_state); __state_->set_value(); } void promise<void>::set_exception(exception_ptr __p) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __throw_future_error(future_errc::no_state); __state_->set_exception(__p); } void promise<void>::set_value_at_thread_exit() { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __throw_future_error(future_errc::no_state); __state_->set_value_at_thread_exit(); } void promise<void>::set_exception_at_thread_exit(exception_ptr __p) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__state_ == nullptr) - throw future_error(make_error_code(future_errc::no_state)); -#endif + __throw_future_error(future_errc::no_state); __state_->set_exception_at_thread_exit(__p); } diff --git a/src/memory.cpp b/src/memory.cpp index 4e0d3af9167eb..77ebe837c73c0 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// -#define _LIBCPP_BUILDING_MEMORY #include "memory" #ifndef _LIBCPP_HAS_NO_THREADS #include "mutex" diff --git a/src/mutex.cpp b/src/mutex.cpp index c36bd5549da8e..c61d34bb885ba 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// -#define _LIBCPP_BUILDING_MUTEX #include "mutex" #include "limits" #include "system_error" diff --git a/src/new.cpp b/src/new.cpp index e228a0d83d8e6..8013d89ae3c24 100644 --- a/src/new.cpp +++ b/src/new.cpp @@ -7,8 +7,6 @@ // //===----------------------------------------------------------------------===// -#define _LIBCPP_BUILDING_NEW - #include <stdlib.h> #include "new" diff --git a/src/shared_mutex.cpp b/src/shared_mutex.cpp index 874aceb1b03a9..6185f15deabd6 100644 --- a/src/shared_mutex.cpp +++ b/src/shared_mutex.cpp @@ -10,7 +10,6 @@ #include "__config" #ifndef _LIBCPP_HAS_NO_THREADS -#define _LIBCPP_BUILDING_SHARED_MUTEX #include "shared_mutex" _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/src/system_error.cpp b/src/system_error.cpp index 72623ea6bc813..06caa6fecd9fe 100644 --- a/src/system_error.cpp +++ b/src/system_error.cpp @@ -9,7 +9,6 @@ #include "__config" -#define _LIBCPP_BUILDING_SYSTEM_ERROR #include "system_error" #include "include/config_elast.h" diff --git a/src/utility.cpp b/src/utility.cpp index e9830e7c24f01..7dccffb73e5a3 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -7,7 +7,6 @@ // //===----------------------------------------------------------------------===// -#define _LIBCPP_BUILDING_UTILITY #include "utility" _LIBCPP_BEGIN_NAMESPACE_STD |
