[PATCH] Extend std::lexicographical_compare optimizations

François Dumont frs.dumont@gmail.com
Mon Dec 9 10:05:00 GMT 2019


Following:

https://gcc.gnu.org/ml/libstdc++/2019-12/msg00028.html

I've done the same kind of work on std::lexicographical_compare algo.

I had to make the internal lexicographical_compare functions return int 
rather than bool cause with bool you can't use a chunck based approach 
unless you double the number of comparison (once a < b and and another b 
< a).

     * include/bits/stl_algobase.h
     (__lexicographical_compare_impl): Return int.
     (__lexicographical_compare::__lc): Likewise.
     (__lexicographical_compare_aux1(_II1, _II1, _II2, _II2)): New.
     (__lexicographical_compare_aux1(_Deque_iterator<>, _Deque_iterator<>,
     _II2, _II2)): New.
     (__lexicographical_compare_aux1(_II1, _II1,
     _Deque_iterator<>, _Deque_iterator<>)): New.
     (__lexicographical_compare_aux1(_Deque_iterator<>, _Deque_iterator<>,
     _Deque_iterator<>, _Deque_iterator<>)): New.
     (__lexicographical_compare_aux): Adapt, call later.
     (__lexicographical_compare_aux(_Safe_iterator<>, _Safe_iterator<>,
     _II2, _II2)): New.
     (__lexicographical_compare_aux(_II1, _II1,
     _Safe_iterator<>, _Safe_iterator<>)): New.
     (__lexicographical_compare_aux(_Safe_iterator<>, _Safe_iterator<>,
     _Safe_iterator<>, _Safe_iterator<>)): New.
     (std::lexicographical_compare): Adapt, call later.
     * include/bits/deque.tcc (__lex_cmp_dit): New.
     (__lexicographical_compare_aux1): Add definitions.
     * include/debug/safe_iterator.tcc (__lexicographical_compare_aux): New.
     * testsuite/25_algorithms/lexicographical_compare/1.cc (test6, test7):
     New.
     * testsuite/25_algorithms/lexicographical_compare/deque_iterators/1.cc:
     New.

Tested under Linux x86_64 normal and debug modes.

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: lex_algo.patch
Type: text/x-patch
Size: 19459 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20191209/f42a29cf/attachment.bin>


More information about the Libstdc++ mailing list