From fb8e0bcea3f6fae8f499fc3279739fdeb56d5826 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 1 Nov 2005 17:36:42 +0000 Subject: [PATCH] Fix performance when using bidirectional iterators: don't use std::distance! [SVN r31531] --- .../boost/regex/v4/perl_matcher_common.hpp | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index af2139b6..54edaa15 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -682,12 +682,32 @@ bool perl_matcher::match_restart_continue() template bool perl_matcher::match_backstep() { - std::ptrdiff_t maxlen = ::boost::re_detail::distance(backstop, position); - if(maxlen < static_cast(pstate)->index) - return false; - std::advance(position, -static_cast(pstate)->index); +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4127) +#endif + if( ::boost::is_random_access_iterator::value) + { + std::ptrdiff_t maxlen = ::boost::re_detail::distance(backstop, position); + if(maxlen < static_cast(pstate)->index) + return false; + std::advance(position, -static_cast(pstate)->index); + } + else + { + int c = static_cast(pstate)->index; + while(c--) + { + if(position == backstop) + return false; + --position; + } + } pstate = pstate->next.p; return true; +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif } template