未验证 提交 6b8ef2f2 编写于 作者: X xiaoye 提交者: GitHub

feat(hihg-performance): use std::move to instead of copy-ctor (#56093)

上级 689bcad5
...@@ -415,59 +415,59 @@ struct EnforceNotMet : public std::exception { ...@@ -415,59 +415,59 @@ struct EnforceNotMet : public std::exception {
* PADDLE_ENFORCE(a, b, "some simple enforce failed between %d numbers", 2) * PADDLE_ENFORCE(a, b, "some simple enforce failed between %d numbers", 2)
*/ */
#define PADDLE_ENFORCE_NOT_NULL(__VAL, ...) \ #define PADDLE_ENFORCE_NOT_NULL(__VAL, ...) \
do { \ do { \
if (UNLIKELY(nullptr == (__VAL))) { \ if (UNLIKELY(nullptr == (__VAL))) { \
auto __summary__ = phi::ErrorSummary(__VA_ARGS__); \ auto __summary__ = phi::ErrorSummary(__VA_ARGS__); \
auto __message__ = ::paddle::string::Sprintf( \ auto __message__ = ::paddle::string::Sprintf( \
"%s\n [Hint: " #__VAL " should not be null.]", \ "%s\n [Hint: " #__VAL " should not be null.]", \
__summary__.error_message()); \ __summary__.error_message()); \
__THROW_ERROR_INTERNAL__( \ __THROW_ERROR_INTERNAL__( \
phi::ErrorSummary(__summary__.code(), __message__)); \ phi::ErrorSummary(__summary__.code(), std::move(__message__))); \
} \ } \
} while (0) } while (0)
#define PADDLE_WARN_NOT_NULL(__VAL, ...) \ #define PADDLE_WARN_NOT_NULL(__VAL, ...) \
do { \ do { \
if (UNLIKELY(nullptr == (__VAL))) { \ if (UNLIKELY(nullptr == (__VAL))) { \
auto __summary__ = phi::ErrorSummary(__VA_ARGS__); \ auto __summary__ = phi::ErrorSummary(__VA_ARGS__); \
auto __message__ = ::paddle::string::Sprintf( \ auto __message__ = ::paddle::string::Sprintf( \
"%s\n [Hint: " #__VAL " should not be null.]", \ "%s\n [Hint: " #__VAL " should not be null.]", \
__summary__.error_message()); \ __summary__.error_message()); \
::phi::enforce::ThrowWarnInternal(__message__); \ ::phi::enforce::ThrowWarnInternal(std::move(__message__)); \
} \ } \
} while (0) } while (0)
#define __PADDLE_BINARY_COMPARE(__VAL1, __VAL2, __CMP, __INV_CMP, ...) \ #define __PADDLE_BINARY_COMPARE(__VAL1, __VAL2, __CMP, __INV_CMP, ...) \
do { \ do { \
auto __val1 = (__VAL1); \ auto __val1 = (__VAL1); \
auto __val2 = (__VAL2); \ auto __val2 = (__VAL2); \
using __TYPE1__ = decltype(__val1); \ using __TYPE1__ = decltype(__val1); \
using __TYPE2__ = decltype(__val2); \ using __TYPE2__ = decltype(__val2); \
using __COMMON_TYPE1__ = \ using __COMMON_TYPE1__ = \
::phi::details::CommonType1<__TYPE1__, __TYPE2__>; \ ::phi::details::CommonType1<__TYPE1__, __TYPE2__>; \
using __COMMON_TYPE2__ = \ using __COMMON_TYPE2__ = \
::phi::details::CommonType2<__TYPE1__, __TYPE2__>; \ ::phi::details::CommonType2<__TYPE1__, __TYPE2__>; \
bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))__CMP( \ bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))__CMP( \
static_cast<__COMMON_TYPE2__>(__val2)); \ static_cast<__COMMON_TYPE2__>(__val2)); \
if (UNLIKELY(!__is_not_error)) { \ if (UNLIKELY(!__is_not_error)) { \
auto __summary__ = phi::ErrorSummary(__VA_ARGS__); \ auto __summary__ = phi::ErrorSummary(__VA_ARGS__); \
constexpr bool __kCanToString__ = \ constexpr bool __kCanToString__ = \
::phi::details::CanToString<__TYPE1__>::kValue && \ ::phi::details::CanToString<__TYPE1__>::kValue && \
::phi::details::CanToString<__TYPE2__>::kValue; \ ::phi::details::CanToString<__TYPE2__>::kValue; \
auto __message__ = ::paddle::string::Sprintf( \ auto __message__ = ::paddle::string::Sprintf( \
"%s\n [Hint: Expected %s " #__CMP \ "%s\n [Hint: Expected %s " #__CMP \
" %s, but received %s " #__INV_CMP " %s.]", \ " %s, but received %s " #__INV_CMP " %s.]", \
__summary__.error_message(), \ __summary__.error_message(), \
#__VAL1, \ #__VAL1, \
#__VAL2, \ #__VAL2, \
::phi::details::BinaryCompareMessageConverter< \ ::phi::details::BinaryCompareMessageConverter< \
__kCanToString__>::Convert(#__VAL1, __val1), \ __kCanToString__>::Convert(#__VAL1, __val1), \
::phi::details::BinaryCompareMessageConverter< \ ::phi::details::BinaryCompareMessageConverter< \
__kCanToString__>::Convert(#__VAL2, __val2)); \ __kCanToString__>::Convert(#__VAL2, __val2)); \
__THROW_ERROR_INTERNAL__( \ __THROW_ERROR_INTERNAL__( \
phi::ErrorSummary(__summary__.code(), __message__)); \ phi::ErrorSummary(__summary__.code(), std::move(__message__))); \
} \ } \
} while (0) } while (0)
#define PADDLE_ENFORCE_EQ(__VAL0, __VAL1, ...) \ #define PADDLE_ENFORCE_EQ(__VAL0, __VAL1, ...) \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册