mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
5510089d45
* Rename simdjson_really_inline -> simdjson_inline I want to change the simdjson_really_inline macro to sometimes not force inlining. After that upcoming change, the name simdjson_really_inline will no longer makes sense. Rename simdjson_really_inline to simdjson_inline. This patch should not change semantics; simdjson_inline still forces inlining as before. Some functions still need to be really inlined for ABI reasons. (GCC's -Wpsabi complains otherwise.) Leave those functions marked as simdjson_really_inline. * Improve build times for debug builds simdjson_inline is used for most simdjson functions. It forces inlining. In unoptimized/debug builds, this can lead to a lot of machine code being generated (especially with Address Sanitizer), causing slow compilation. Change simdjson_inline to force inlining only for optimized builds. Sometimes, the programmer might want a slightly-optimized build and want fast compilation (e.g. GCC's -Og mode). Allow simdjson users to define the simdjson_inline macro themselves (e.g. on the command line: -Dsimdjson_inline=inline) in cases where the default behavior is undesired. This patch reduced build times by over 75% for ondemand_object_tests.cpp with GCC 9.4.0 and CMAKE_BUILD_TYPE=Debug on my AMD 5950X: Before: 6.885 6.683 6.971 6.957 6.949 seconds (5 samples) After: 1.492 1.551 1.494 1.490 1.531 seconds (5 samples)
81 lines
2.7 KiB
C++
81 lines
2.7 KiB
C++
namespace simdjson {
|
|
namespace SIMDJSON_IMPLEMENTATION {
|
|
|
|
//
|
|
// internal::implementation_simdjson_result_base<T> inline implementation
|
|
//
|
|
|
|
template<typename T>
|
|
simdjson_inline void implementation_simdjson_result_base<T>::tie(T &value, error_code &error) && noexcept {
|
|
error = this->second;
|
|
if (!error) {
|
|
value = std::forward<implementation_simdjson_result_base<T>>(*this).first;
|
|
}
|
|
}
|
|
|
|
template<typename T>
|
|
simdjson_warn_unused simdjson_inline error_code implementation_simdjson_result_base<T>::get(T &value) && noexcept {
|
|
error_code error;
|
|
std::forward<implementation_simdjson_result_base<T>>(*this).tie(value, error);
|
|
return error;
|
|
}
|
|
|
|
template<typename T>
|
|
simdjson_inline error_code implementation_simdjson_result_base<T>::error() const noexcept {
|
|
return this->second;
|
|
}
|
|
|
|
#if SIMDJSON_EXCEPTIONS
|
|
|
|
template<typename T>
|
|
simdjson_inline T& implementation_simdjson_result_base<T>::value() & noexcept(false) {
|
|
if (error()) { throw simdjson_error(error()); }
|
|
return this->first;
|
|
}
|
|
|
|
template<typename T>
|
|
simdjson_inline T&& implementation_simdjson_result_base<T>::value() && noexcept(false) {
|
|
return std::forward<implementation_simdjson_result_base<T>>(*this).take_value();
|
|
}
|
|
|
|
template<typename T>
|
|
simdjson_inline T&& implementation_simdjson_result_base<T>::take_value() && noexcept(false) {
|
|
if (error()) { throw simdjson_error(error()); }
|
|
return std::forward<T>(this->first);
|
|
}
|
|
|
|
template<typename T>
|
|
simdjson_inline implementation_simdjson_result_base<T>::operator T&&() && noexcept(false) {
|
|
return std::forward<implementation_simdjson_result_base<T>>(*this).take_value();
|
|
}
|
|
|
|
#endif // SIMDJSON_EXCEPTIONS
|
|
|
|
template<typename T>
|
|
simdjson_inline const T& implementation_simdjson_result_base<T>::value_unsafe() const& noexcept {
|
|
return this->first;
|
|
}
|
|
|
|
template<typename T>
|
|
simdjson_inline T& implementation_simdjson_result_base<T>::value_unsafe() & noexcept {
|
|
return this->first;
|
|
}
|
|
|
|
template<typename T>
|
|
simdjson_inline T&& implementation_simdjson_result_base<T>::value_unsafe() && noexcept {
|
|
return std::forward<T>(this->first);
|
|
}
|
|
|
|
template<typename T>
|
|
simdjson_inline implementation_simdjson_result_base<T>::implementation_simdjson_result_base(T &&value, error_code error) noexcept
|
|
: first{std::forward<T>(value)}, second{error} {}
|
|
template<typename T>
|
|
simdjson_inline implementation_simdjson_result_base<T>::implementation_simdjson_result_base(error_code error) noexcept
|
|
: implementation_simdjson_result_base(T{}, error) {}
|
|
template<typename T>
|
|
simdjson_inline implementation_simdjson_result_base<T>::implementation_simdjson_result_base(T &&value) noexcept
|
|
: implementation_simdjson_result_base(std::forward<T>(value), SUCCESS) {}
|
|
|
|
} // namespace SIMDJSON_IMPLEMENTATION
|
|
} // namespace simdjson
|