summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/regex_compiler.h
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2014-06-02 19:36:14 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2014-06-02 19:36:14 +0000
commitec42ae9cd9aa343e82395d901e30d19a5da5bf38 (patch)
treeee0541ddd6a618216ef62242a2df4be566a14a2e /libstdc++-v3/include/bits/regex_compiler.h
parent19c83bfb5d8140d63d59af338bc8a0400ae3df62 (diff)
* include/bits/regex_compiler.h (__detail::_BracketMatcher): Reorder
members to avoid wasted space when not using a cache. (__detail::_BracketMatcher::_M_ready()): Sort and deduplicate set. * include/bits/regex_compiler.tcc (__detail::_BracketMatcher::_M_apply(_CharT, false_type)): Use binary search on set. * include/bits/regex_executor.h (__detail::_Executor::_Match_mode): New enumeration type to indicate match mode. (__detail::_Executor::_State_info): New type holding members only needed in BFS-mode. Replace unique_ptr<vector<bool>> with unique_ptr<bool[]>. (__detail::_Executor::_M_rep_once_more, __detail::_Executor::_M_dfs): Replace template parameter with run-time function parameter. (__detail::_Executor::_M_main): Likewise. Dispatch to ... (__detail::_Executor::_M_main_dispatch): New overloaded functions to implement DFS and BFS mode. * include/bits/regex_executor.tcc (__detail::_Executor::_M_main): Split implementation into ... (__detail::_Executor::_M_main_dispatch): New overloaded functions. (__detail::_Executor::_M_lookahead): Create nested executor on stack. (__detail::_Executor::_M_rep_once_more): Pass match mode as function argument instead of template argument. (__detail::_Executor::_M_dfs): Likewise. * include/bits/regex_scanner.tcc: Fix typos in comments. * testsuite/performance/28_regex/range.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211143 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits/regex_compiler.h')
-rw-r--r--libstdc++-v3/include/bits/regex_compiler.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h
index 52f7235c8dbb..ca116de53af4 100644
--- a/libstdc++-v3/include/bits/regex_compiler.h
+++ b/libstdc++-v3/include/bits/regex_compiler.h
@@ -43,7 +43,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct _BracketMatcher;
/**
- * @brief Builds an NFA from an input iterator interval.
+ * @brief Builds an NFA from an input iterator range.
*
* The %_TraitsT type should fulfill requirements [28.3].
*/
@@ -329,7 +329,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator()(_CharT __ch) const
{
_GLIBCXX_DEBUG_ASSERT(_M_is_ready);
- return _M_apply(__ch, _IsChar());
+ return _M_apply(__ch, _UseCache());
}
void
@@ -400,21 +400,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
_M_ready()
{
- _M_make_cache(_IsChar());
+ std::sort(_M_char_set.begin(), _M_char_set.end());
+ auto __end = std::unique(_M_char_set.begin(), _M_char_set.end());
+ _M_char_set.erase(__end, _M_char_set.end());
+ _M_make_cache(_UseCache());
#ifdef _GLIBCXX_DEBUG
_M_is_ready = true;
#endif
}
private:
- typedef typename is_same<_CharT, char>::type _IsChar;
+ // Currently we only use the cache for char
+ typedef typename std::is_same<_CharT, char>::type _UseCache;
+
+ static constexpr size_t
+ _S_cache_size() { return 1ul << (sizeof(_CharT) * __CHAR_BIT__); }
+
struct _Dummy { };
- typedef typename conditional<_IsChar::value,
- std::bitset<1 << (8 * sizeof(_CharT))>,
- _Dummy>::type _CacheT;
- typedef typename make_unsigned<_CharT>::type _UnsignedCharT;
+ typedef typename std::conditional<_UseCache::value,
+ std::bitset<_S_cache_size()>,
+ _Dummy>::type _CacheT;
+ typedef typename std::make_unsigned<_CharT>::type _UnsignedCharT;
- private:
bool
_M_apply(_CharT __ch, false_type) const;
@@ -425,9 +432,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
_M_make_cache(true_type)
{
- for (size_t __i = 0; __i < _M_cache.size(); __i++)
- _M_cache[static_cast<_UnsignedCharT>(__i)] =
- _M_apply(__i, false_type());
+ for (unsigned __i = 0; __i < _M_cache.size(); __i++)
+ _M_cache[__i] = _M_apply(static_cast<_CharT>(__i), false_type());
}
void
@@ -435,7 +441,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ }
private:
- _CacheT _M_cache;
std::vector<_CharT> _M_char_set;
std::vector<_StringT> _M_equiv_set;
std::vector<pair<_StrTransT, _StrTransT>> _M_range_set;
@@ -444,6 +449,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_TransT _M_translator;
const _TraitsT& _M_traits;
bool _M_is_non_matching;
+ _CacheT _M_cache;
#ifdef _GLIBCXX_DEBUG
bool _M_is_ready;
#endif