In the event the internal function __init is called with an empty string the code will take unnecessary extra steps, in addition, the code generated might be overall greater because, to my understanding, when initializing a string with an empty `const char*` "" (like in this case), the compiler might be unable to deduce the string is indeed empty at compile time and more code is generated. The goal of this patch is to make a new internal function that will accept just an error code skipping the empty string argument. It should skip the unnecessary steps and in the event `if (ec)` is `false`, it will return an empty string using the correct ctor, avoiding any extra code generation issues. After the conversation about this patch matured in the libcxx channel on the LLVM Discord server, the patch was analyzed quickly with "Compiler Explorer" and other tools and it was discovered that it does indeed reduce the amount of code generated when using the latest stable clang version (16) which in turn produces faster code. This patch targets LLVM 18 as it will break the ABI by addressing https://github.com/llvm/llvm-project/issues/63985 Benchmark tests run on other machines as well show in the best case, that the new version without the extra string as an argument performs 10 times faster. On the buildkite CI run it shows the new code takes less CPU time as well. In conclusion, the new code should also just appear cleaner because there are fewer checks to do when there is no message. Reviewed By: #libc, philnik Spies: emaste, nemanjai, philnik, libcxx-commits Differential Revision: https://reviews.llvm.org/D155820
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
// -*- C++ -*-
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef _LIBCPP___SYSTEM_ERROR_SYSTEM_ERROR_H
|
|
#define _LIBCPP___SYSTEM_ERROR_SYSTEM_ERROR_H
|
|
|
|
#include <__config>
|
|
#include <__system_error/error_category.h>
|
|
#include <__system_error/error_code.h>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
|
# pragma GCC system_header
|
|
#endif
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
class _LIBCPP_EXPORTED_FROM_ABI system_error : public runtime_error {
|
|
error_code __ec_;
|
|
|
|
public:
|
|
system_error(error_code __ec, const string& __what_arg);
|
|
system_error(error_code __ec, const char* __what_arg);
|
|
system_error(error_code __ec);
|
|
system_error(int __ev, const error_category& __ecat, const string& __what_arg);
|
|
system_error(int __ev, const error_category& __ecat, const char* __what_arg);
|
|
system_error(int __ev, const error_category& __ecat);
|
|
_LIBCPP_HIDE_FROM_ABI system_error(const system_error&) _NOEXCEPT = default;
|
|
~system_error() _NOEXCEPT override;
|
|
|
|
_LIBCPP_HIDE_FROM_ABI const error_code& code() const _NOEXCEPT { return __ec_; }
|
|
};
|
|
|
|
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_system_error(int __ev, const char* __what_arg);
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
#endif // _LIBCPP___SYSTEM_ERROR_SYSTEM_ERROR_H
|