|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84999 - trunk/boost/regex/v4
From: john_at_[hidden]
Date: 2013-07-10 12:10:44
Author: johnmaddock
Date: 2013-07-10 12:10:44 EDT (Wed, 10 Jul 2013)
New Revision: 84999
URL: http://svn.boost.org/trac/boost/changeset/84999
Log:
Optimise iterator advances for slow (non-random access) iterators.
Text files modified:
trunk/boost/regex/v4/perl_matcher_non_recursive.hpp | 24 +++++++++++++++++++++---
trunk/boost/regex/v4/perl_matcher_recursive.hpp | 16 ++++++++++++++--
2 files changed, 35 insertions(+), 5 deletions(-)
Modified: trunk/boost/regex/v4/perl_matcher_non_recursive.hpp
==============================================================================
--- trunk/boost/regex/v4/perl_matcher_non_recursive.hpp Wed Jul 10 12:08:57 2013 (r84998)
+++ trunk/boost/regex/v4/perl_matcher_non_recursive.hpp 2013-07-10 12:10:44 EDT (Wed, 10 Jul 2013) (r84999)
@@ -703,7 +703,13 @@
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
- std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
+ // Move end forward by "desired", preferably without using distance or advance if we can
+ // as these can be slow for some iterator types.
+ std::size_t len = (desired == (std::numeric_limits<std::size_t>::max)()) ? 0u : ::boost::re_detail::distance(position, last);
+ if(desired >= len)
+ end = last;
+ else
+ std::advance(end, desired);
BidiIterator origin(position);
while((position != end) && (traits_inst.translate(*position, icase) == what))
{
@@ -771,7 +777,13 @@
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
- std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
+ // Move end forward by "desired", preferably without using distance or advance if we can
+ // as these can be slow for some iterator types.
+ std::size_t len = (desired == (std::numeric_limits<std::size_t>::max)()) ? 0u : ::boost::re_detail::distance(position, last);
+ if(desired >= len)
+ end = last;
+ else
+ std::advance(end, desired);
BidiIterator origin(position);
while((position != end) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
@@ -840,7 +852,13 @@
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
- std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
+ // Move end forward by "desired", preferably without using distance or advance if we can
+ // as these can be slow for some iterator types.
+ std::size_t len = (desired == (std::numeric_limits<std::size_t>::max)()) ? 0u : ::boost::re_detail::distance(position, last);
+ if(desired >= len)
+ end = last;
+ else
+ std::advance(end, desired);
BidiIterator origin(position);
while((position != end) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
Modified: trunk/boost/regex/v4/perl_matcher_recursive.hpp
==============================================================================
--- trunk/boost/regex/v4/perl_matcher_recursive.hpp Wed Jul 10 12:08:57 2013 (r84998)
+++ trunk/boost/regex/v4/perl_matcher_recursive.hpp 2013-07-10 12:10:44 EDT (Wed, 10 Jul 2013) (r84999)
@@ -641,7 +641,13 @@
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
- std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
+ // Move end forward by "desired", preferably without using distance or advance if we can
+ // as these can be slow for some iterator types.
+ std::size_t len = (desired == (std::numeric_limits<std::size_t>::max)()) ? 0u : ::boost::re_detail::distance(position, last);
+ if(desired >= len)
+ end = last;
+ else
+ std::advance(end, desired);
BidiIterator origin(position);
while((position != end) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
@@ -731,7 +737,13 @@
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
- std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
+ // Move end forward by "desired", preferably without using distance or advance if we can
+ // as these can be slow for some iterator types.
+ std::size_t len = (desired == (std::numeric_limits<std::size_t>::max)()) ? 0u : ::boost::re_detail::distance(position, last);
+ if(desired >= len)
+ end = last;
+ else
+ std::advance(end, desired);
BidiIterator origin(position);
while((position != end) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk