Skip to content

Commit fc9fdba

Browse files
committed
[libc++] Mark __{emplace,push}_back_slow_path as noinline
1 parent 69f3552 commit fc9fdba

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

libcxx/include/__vector/vector.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,21 @@ vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) {
11281128
return this->__end_;
11291129
}
11301130

1131+
template <class _If, class _Else>
1132+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __if_likely_else(bool __cond, _If __if, _Else __else) {
1133+
if (__builtin_constant_p(__cond)) {
1134+
if (__cond)
1135+
__if();
1136+
else
1137+
__else();
1138+
} else {
1139+
if (__cond) [[__likely__]]
1140+
__if();
1141+
else
1142+
__else();
1143+
}
1144+
}
1145+
11311146
template <class _Tp, class _Allocator>
11321147
template <class... _Args>
11331148
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline
@@ -1138,12 +1153,14 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline
11381153
#endif
11391154
vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
11401155
pointer __end = this->__end_;
1141-
if (__end < this->__cap_) {
1142-
__emplace_back_assume_capacity(std::forward<_Args>(__args)...);
1143-
++__end;
1144-
} else {
1145-
__end = __emplace_back_slow_path(std::forward<_Args>(__args)...);
1146-
}
1156+
std::__if_likely_else(
1157+
__end < this->__cap_,
1158+
[&] {
1159+
__emplace_back_assume_capacity(std::forward<_Args>(__args)...);
1160+
++__end;
1161+
},
1162+
[&] { __end = __emplace_back_slow_path(std::forward<_Args>(__args)...); });
1163+
11471164
this->__end_ = __end;
11481165
#if _LIBCPP_STD_VER >= 17
11491166
return *(__end - 1);

0 commit comments

Comments
 (0)