[libcxx] r226641 - tuple: Make operator<() linear instead of exponential
Duncan P. N. Exon Smith
dexonsmith at apple.com
Tue Jan 20 18:51:17 PST 2015
Author: dexonsmith
Date: Tue Jan 20 20:51:17 2015
New Revision: 226641
URL: http://llvm.org/viewvc/llvm-project?rev=226641&view=rev
Log:
tuple: Make operator<() linear instead of exponential
Patch by Matthew Dempsky!
Modified:
libcxx/trunk/include/tuple
Modified: libcxx/trunk/include/tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/tuple?rev=226641&r1=226640&r2=226641&view=diff
==============================================================================
--- libcxx/trunk/include/tuple (original)
+++ libcxx/trunk/include/tuple Tue Jan 20 20:51:17 2015
@@ -927,8 +927,12 @@ struct __tuple_less
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _Tp& __x, const _Up& __y)
{
- return __tuple_less<_Ip-1>()(__x, __y) ||
- (!__tuple_less<_Ip-1>()(__y, __x) && _VSTD::get<_Ip-1>(__x) < _VSTD::get<_Ip-1>(__y));
+ const size_t __idx = tuple_size<_Tp>::value - _Ip;
+ if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
+ return true;
+ if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
+ return false;
+ return __tuple_less<_Ip-1>()(__x, __y);
}
};
More information about the cfe-commits
mailing list