/////////////////////////////////////////////////////////////////////////////// // optimize.hpp // // Copyright 2004 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_XPRESSIVE_DETAIL_CORE_OPTIMIZE_HPP_EAN_10_04_2005 #define BOOST_XPRESSIVE_DETAIL_CORE_OPTIMIZE_HPP_EAN_10_04_2005 #include #include #include #include #include #include #include #include namespace boost { namespace xpressive { namespace detail { /////////////////////////////////////////////////////////////////////////////// // optimize_regex // template inline void optimize_regex(regex_impl &impl, Traits const &traits, mpl::true_) { typedef typename iterator_value::type char_type; // optimization: get the peek chars OR the boyer-moore search string hash_peek_bitset bset; xpression_peeker peeker(&bset, traits); impl.xpr_->peek(peeker); // if we have a leading string literal, initialize a boyer-moore struct with it std::pair const *, bool> str = peeker.get_string(); if(0 != str.first) { impl.finder_.reset ( new boyer_moore_finder ( str.first->data() , str.first->data() + str.first->size() , traits , str.second ) ); } else if(peeker.line_start()) { impl.finder_.reset ( new line_start_finder(traits) ); } else if(256 != bset.count()) { impl.finder_.reset ( new hash_peek_finder(bset) ); } } /////////////////////////////////////////////////////////////////////////////// // optimize_regex // template inline void optimize_regex(regex_impl &impl, Traits const &traits, mpl::false_) { typedef typename iterator_value::type char_type; // optimization: get the peek chars OR the line start finder hash_peek_bitset bset; xpression_peeker peeker(&bset, traits); impl.xpr_->peek(peeker); if(peeker.line_start()) { impl.finder_.reset ( new line_start_finder(traits) ); } else if(256 != bset.count()) { impl.finder_.reset ( new hash_peek_finder(bset) ); } } }}} // namespace boost::xpressive #endif