Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86148 - trunk/libs/log/src
From: andrey.semashev_at_[hidden]
Date: 2013-10-03 15:40:55


Author: andysem
Date: 2013-10-03 15:40:55 EDT (Thu, 03 Oct 2013)
New Revision: 86148
URL: http://svn.boost.org/trac/boost/changeset/86148

Log:
Optimized compile times and reduced binary size. Hopefully, this will resolve linking timeouts in the tests.

Text files modified:
   trunk/libs/log/src/default_filter_factory.cpp | 174 ++++++++++++---------------------------
   1 files changed, 54 insertions(+), 120 deletions(-)

Modified: trunk/libs/log/src/default_filter_factory.cpp
==============================================================================
--- trunk/libs/log/src/default_filter_factory.cpp Thu Oct 3 15:25:58 2013 (r86147)
+++ trunk/libs/log/src/default_filter_factory.cpp 2013-10-03 15:40:55 EDT (Thu, 03 Oct 2013) (r86148)
@@ -16,15 +16,9 @@
 #if !defined(BOOST_LOG_WITHOUT_SETTINGS_PARSERS) && !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
 
 #include <string>
-#include <boost/move/core.hpp>
-#include <boost/move/utility.hpp>
-#include <boost/utility/enable_if.hpp>
 #include <boost/mpl/copy.hpp>
-#include <boost/mpl/contains.hpp>
 #include <boost/mpl/back_inserter.hpp>
 #include <boost/spirit/include/qi_core.hpp>
-#include <boost/spirit/include/qi_eoi.hpp>
-#include <boost/spirit/include/qi_as.hpp>
 #include <boost/log/exceptions.hpp>
 #include <boost/log/expressions/predicates/has_attr.hpp>
 #include <boost/log/utility/type_dispatch/standard_types.hpp>
@@ -33,7 +27,6 @@
 #include <boost/log/utility/functional/begins_with.hpp>
 #include <boost/log/utility/functional/ends_with.hpp>
 #include <boost/log/utility/functional/contains.hpp>
-#include <boost/log/utility/functional/as_action.hpp>
 #include <boost/log/detail/code_conversion.hpp>
 #if defined(BOOST_LOG_USE_CHAR) && defined(BOOST_LOG_USE_WCHAR_T)
 #include <boost/fusion/container/set.hpp>
@@ -100,10 +93,7 @@
     }
 
     template< typename T >
- typename boost::enable_if<
- mpl::contains< log::string_types::type, T >,
- result_type
- >::type operator() (T const& val) const
+ result_type operator() (T const& val) const
     {
         typedef std::basic_string< typename T::value_type > operand_type;
         return relation_type::operator() (val, fusion::at_key< operand_type >(m_operands));
@@ -170,99 +160,32 @@
     {
     }
 
- template< typename T >
- typename boost::enable_if<
- mpl::contains< log::string_types, T >,
- result_type
- >::type operator() (T const& val) const
+ template< typename CharT, typename TraitsT, typename AllocatorT >
+ result_type operator() (std::basic_string< CharT, TraitsT, AllocatorT > const& val) const
     {
         return base_type::operator() (val);
     }
 
- template< typename T >
- typename boost::disable_if<
- mpl::contains< log::string_types, T >,
- result_type
- >::type operator() (T const& val) const
- {
- return relation_type::operator() (val, m_numeric_operand);
- }
-
-private:
- const numeric_type m_numeric_operand;
-};
-
-
-template< typename RelationT >
-struct on_string_argument
-{
- typedef void result_type;
-
- on_string_argument(attribute_name const& name, filter& f) : m_name(name), m_filter(f)
- {
- }
-
- template< typename StringT >
- result_type operator() (StringT const& val) const
- {
- typedef string_predicate< RelationT > predicate;
- m_filter = predicate_wrapper< log::string_types, predicate >(m_name, predicate(RelationT(), val));
- }
-
-private:
- attribute_name m_name;
- filter& m_filter;
-};
-
-template< typename RelationT, typename StringT >
-struct on_integral_argument
-{
- typedef void result_type;
-
- on_integral_argument(attribute_name const& name, StringT const& operand, filter& f) : m_name(name), m_operand(operand), m_filter(f)
+ template< typename CharT, typename TraitsT >
+ result_type operator() (basic_string_literal< CharT, TraitsT > const& val) const
     {
+ return base_type::operator() (val);
     }
 
- result_type operator() (long val) const
+ template< typename T >
+ result_type operator() (T const& val) const
     {
- typedef numeric_predicate< long, RelationT > predicate;
- typedef mpl::copy<
- log::string_types,
- mpl::back_inserter< log::numeric_types >
- >::type value_types;
- m_filter = predicate_wrapper< value_types, predicate >(m_name, predicate(RelationT(), m_operand, val));
+ return relation_type::operator() (val, m_numeric_operand);
     }
 
 private:
- attribute_name m_name;
- StringT const& m_operand;
- filter& m_filter;
+ const numeric_type m_numeric_operand;
 };
 
-template< typename RelationT, typename StringT >
-struct on_fp_argument
-{
- typedef void result_type;
-
- on_fp_argument(attribute_name const& name, StringT const& operand, filter& f) : m_name(name), m_operand(operand), m_filter(f)
- {
- }
-
- result_type operator() (double val) const
- {
- typedef numeric_predicate< double, RelationT > predicate;
- typedef mpl::copy<
- log::string_types,
- mpl::back_inserter< log::floating_point_types >
- >::type value_types;
- m_filter = predicate_wrapper< value_types, predicate >(m_name, predicate(RelationT(), m_operand, val));
- }
-
-private:
- attribute_name m_name;
- StringT const& m_operand;
- filter& m_filter;
-};
+typedef mpl::copy<
+ log::string_types,
+ mpl::back_inserter< log::floating_point_types >
+>::type floating_point_and_string_types;
 
 } // namespace
 
@@ -314,21 +237,27 @@
 {
     typedef log::aux::char_constants< char_type > constants;
 
- filter f;
     if (rel == constants::begins_with_keyword())
- on_string_argument< begins_with_fun >(name, f)(arg);
+ {
+ typedef string_predicate< begins_with_fun > predicate;
+ return predicate_wrapper< log::string_types, predicate >(name, predicate(begins_with_fun(), arg));
+ }
     else if (rel == constants::ends_with_keyword())
- on_string_argument< ends_with_fun >(name, f)(arg);
+ {
+ typedef string_predicate< ends_with_fun > predicate;
+ return predicate_wrapper< log::string_types, predicate >(name, predicate(ends_with_fun(), arg));
+ }
     else if (rel == constants::contains_keyword())
- on_string_argument< contains_fun >(name, f)(arg);
- else if (rel == constants::matches_keyword())
- f = parse_matches_relation(name, arg);
- else
+ {
+ typedef string_predicate< contains_fun > predicate;
+ return predicate_wrapper< log::string_types, predicate >(name, predicate(contains_fun(), arg));
+ }
+ else if (rel != constants::matches_keyword())
     {
         BOOST_LOG_THROW_DESCR(parse_error, "The custom attribute relation \"" + log::aux::to_narrow(rel) + "\" is not supported");
     }
 
- return boost::move(f);
+ return parse_matches_relation(name, arg);
 }
 
 
@@ -337,28 +266,33 @@
 template< typename RelationT >
 filter default_filter_factory< CharT >::parse_argument(attribute_name const& name, string_type const& arg)
 {
- typedef log::aux::encoding_specific< typename log::aux::encoding< char_type >::type > encoding_specific;
- const qi::real_parser< double, qi::strict_real_policies< double > > real_;
-
- filter f;
- const on_fp_argument< RelationT, string_type > on_fp(name, arg, f);
- const on_integral_argument< RelationT, string_type > on_int(name, arg, f);
- const on_string_argument< RelationT > on_str(name, f);
-
- const bool res = qi::parse
- (
- arg.c_str(), arg.c_str() + arg.size(),
- (
- real_[boost::log::as_action(on_fp)] |
- qi::long_[boost::log::as_action(on_int)] |
- qi::as< string_type >()[ +encoding_specific::print ][boost::log::as_action(on_str)]
- ) >> qi::eoi
- );
+ const char_type* begin = arg.c_str();
+ const char_type* const end = begin + arg.size();
 
- if (!res)
- BOOST_LOG_THROW_DESCR(parse_error, "Failed to parse relation operand");
-
- return boost::move(f);
+ double real_val = 0.0;
+ const qi::real_parser< double, qi::strict_real_policies< double > > real_;
+ if (qi::parse(begin, end, real_, real_val) && begin == end)
+ {
+ typedef numeric_predicate< double, RelationT > predicate;
+ typedef floating_point_and_string_types value_types;
+ return predicate_wrapper< value_types, predicate >(name, predicate(RelationT(), arg, real_val));
+ }
+ else
+ {
+ begin = arg.c_str();
+ long int_val = 0;
+ if (qi::parse(begin, end, qi::long_, int_val) && begin == end)
+ {
+ typedef numeric_predicate< long, RelationT > predicate;
+ typedef default_attribute_types value_types;
+ return predicate_wrapper< value_types, predicate >(name, predicate(RelationT(), arg, int_val));
+ }
+ else
+ {
+ typedef string_predicate< RelationT > predicate;
+ return predicate_wrapper< log::string_types, predicate >(name, predicate(RelationT(), arg));
+ }
+ }
 }
 
 // Explicitly instantiate factory implementation


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