forked from boostorg/regex
Fix performance when using bidirectional iterators: don't use std::distance!
[SVN r31531]
This commit is contained in:
@ -681,13 +681,33 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_restart_continue()
|
|||||||
|
|
||||||
template <class BidiIterator, class Allocator, class traits>
|
template <class BidiIterator, class Allocator, class traits>
|
||||||
bool perl_matcher<BidiIterator, Allocator, traits>::match_backstep()
|
bool perl_matcher<BidiIterator, Allocator, traits>::match_backstep()
|
||||||
|
{
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable:4127)
|
||||||
|
#endif
|
||||||
|
if( ::boost::is_random_access_iterator<BidiIterator>::value)
|
||||||
{
|
{
|
||||||
std::ptrdiff_t maxlen = ::boost::re_detail::distance(backstop, position);
|
std::ptrdiff_t maxlen = ::boost::re_detail::distance(backstop, position);
|
||||||
if(maxlen < static_cast<const re_brace*>(pstate)->index)
|
if(maxlen < static_cast<const re_brace*>(pstate)->index)
|
||||||
return false;
|
return false;
|
||||||
std::advance(position, -static_cast<const re_brace*>(pstate)->index);
|
std::advance(position, -static_cast<const re_brace*>(pstate)->index);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int c = static_cast<const re_brace*>(pstate)->index;
|
||||||
|
while(c--)
|
||||||
|
{
|
||||||
|
if(position == backstop)
|
||||||
|
return false;
|
||||||
|
--position;
|
||||||
|
}
|
||||||
|
}
|
||||||
pstate = pstate->next.p;
|
pstate = pstate->next.p;
|
||||||
return true;
|
return true;
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class BidiIterator, class Allocator, class traits>
|
template <class BidiIterator, class Allocator, class traits>
|
||||||
|
Reference in New Issue
Block a user