|
Boost : |
From: David Manura (dm.list_at_[hidden])
Date: 2006-07-20 09:20:27
Janek Kozicki <janek_listy <at> wp.pl> writes:
> wow. It's a good programming practice to use const& everywhere where
> possible. T'd love to see this patch applied. Thanks!
The below second patch provides much further improvement. I realize the second
patch is somewhat of a hack, but it illustrates where the rest of the slowdown
is coming from and may suggest a better way of fixing it.
Before second patch:
MSVC++2005: 1: 2406 2: 2359 3: 1500 4: 297 (run times)
G++/Intel: 1: 703 2: 703 3: 188 4: 172
After second patch:
MSVC++2005: 1: 235 2: 250 3: 251 4: 282 (run times)
G++/Intel: 1: 141 2: 141 3: 109 4: 172
There's likely other places in the string algorithms code that could benefit
from similar changes.
--davidm
<snip>
diff -udr boost/boost/algorithm/string/detail/classification.hpp
boost-patched/boost/algorithm/string/detail/classification.hpp
--- boost/boost/algorithm/string/detail/classification.hpp 2006-04-16
05:46:34.000000000 -0400
+++ boost-patched/boost/algorithm/string/detail/classification.hpp 2006-07-20
08:58:02.359849300 -0400
@@ -21,6 +21,7 @@
#include <boost/algorithm/string/predicate_facade.hpp>
#include <boost/type_traits/remove_const.hpp>
+#include <locale>
namespace boost {
namespace algorithm {
@@ -36,14 +37,15 @@
template <class Args> struct sig { typedef bool type; };
// Constructor from a locale
- is_classifiedF(std::ctype_base::mask Type, std::locale const &
Loc = std::locale()) :
+ is_classifiedF(std::ctype_base::mask Type, std::locale const &
Loc = default_locale_) :
m_Type(Type), m_Locale(Loc) {}
// Operation
template<typename CharT>
bool operator()( CharT Ch ) const
{
- return std::use_facet< std::ctype<CharT> >(m_Locale).is(
m_Type, Ch );
+ static const std::ctype<CharT> & data = std::use_facet<
std::ctype<CharT> >(m_Locale);
+ return data.is( m_Type, Ch );
}
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) &&
(__BORLANDC__ <= 0x582) && !defined(_USE_OLD_RW_STL)
@@ -56,7 +58,7 @@
private:
const std::ctype_base::mask m_Type;
- const std::locale m_Locale;
+ const std::locale & m_Locale;
};
// is_any_of functor
</snip>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk