[Patch] Patch set for regex instantiation

Tim Shen timshen91@gmail.com
Sun Jan 12 00:48:00 GMT 2014


Here're 4 patches that finally led the _Compiler's instantiation and
some other optimization for compiling time.

1) Create class _ScannerBase to make _Scanner pithier. Move const
static members to src/c++11/regex.cc.
2) Make _Compiler and _Scanner `_FwdIter independent`. We store the
input regex string in basic_regex as a basic_string; but when
compiling it, const _CharT* is used.
3) Avoid using std::map, std::set and std::queue to reduce compile time.
4) Instantiate _Compiler<regex_traits<char>> and
_Compiler<regex_traits<wchar_t>>. Export vector<string> and
vector<wstring>'s ctor and dtor as well for _Compiler's denpendency.

Now compiling time reduced about a half, and .so increases by about
100kb (release version).

These patches are based on my previous patch. Is that Ok to commit?

Booted, and tested with -m64 and -m32; But check-debug failed some
23_containers/* cases? I suppose it's not my problem?

Thank you!


-- 
Regards,
Tim Shen
-------------- next part --------------
commit 1a5d55abd495aa8f56086addbac25422fa1abe8b
Author: tim <timshen91@gmail.com>
Date:   Fri Jan 10 18:06:38 2014 -0500

    2014-01-11  Tim Shen  <timshen91@gmail.com>
    
    	* config/abi/pre/gnu.ver: Export _ScannerBase const static members.
    	* include/bits/regex_compiler.h: Change _ScannerT into char-type
    	templated.
    	* include/bits/regex_scanner.h (_Scanner<>::_Scanner()): Separate
    	_ScannerBase from _Scanner; Change _Scanner's template argument from
    	_FwdIter to _CharT. Avoid use of std::map and std::set by using arrays
    	instead.
    	* include/bits/regex_scanner.tcc (_Scanner<>::_Scanner(),
    	_Scanner<>::_M_scan_normal(), _Scanner<>::_M_eat_escape_ecma(),
    	_Scanner<>::_M_eat_escape_posix(), _Scanner<>::_M_eat_escape_awk()):
    	Likewise.
    	* include/std/regex: Add <cstring> for using strchrnul.
    	* src/c++11/regex.cc: Add _ScannerBase const static member definitions.

diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 2010bd3..147b11b 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -1371,6 +1371,9 @@ GLIBCXX_3.4.20 {
     # std::regex_error::regex_error(std::regex_constants::error_type)
     _ZNSt11regex_errorC[01]ENSt15regex_constants10error_typeE;
 
+    # std::__detail::_ScannerBase::*
+    _ZNSt8__detail12_ScannerBase*;
+
 } GLIBCXX_3.4.19;
 
 # Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h
index b73fe30..e692726 100644
--- a/libstdc++-v3/include/bits/regex_compiler.h
+++ b/libstdc++-v3/include/bits/regex_compiler.h
@@ -59,7 +59,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return make_shared<_RegexT>(std::move(_M_nfa)); }
 
     private:
-      typedef _Scanner<_FwdIter>                              _ScannerT;
+      typedef _Scanner<typename _TraitsT::char_type>          _ScannerT;
       typedef typename _ScannerT::_TokenT                     _TokenT;
       typedef _StateSeq<_TraitsT>                     	      _StateSeqT;
       typedef std::stack<_StateSeqT, std::vector<_StateSeqT>> _StackT;
diff --git a/libstdc++-v3/include/bits/regex_scanner.h b/libstdc++-v3/include/bits/regex_scanner.h
index d113c5d..a05f46e 100644
--- a/libstdc++-v3/include/bits/regex_scanner.h
+++ b/libstdc++-v3/include/bits/regex_scanner.h
@@ -39,6 +39,120 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    * @{
    */
 
+  struct _ScannerBase
+  {
+  public:
+    /// Token types returned from the scanner.
+    enum _TokenT
+    {
+      _S_token_anychar,
+      _S_token_ord_char,
+      _S_token_oct_num,
+      _S_token_hex_num,
+      _S_token_backref,
+      _S_token_subexpr_begin,
+      _S_token_subexpr_no_group_begin,
+      _S_token_subexpr_lookahead_begin, // neg if _M_value[0] == 'n'
+      _S_token_subexpr_end,
+      _S_token_bracket_begin,
+      _S_token_bracket_neg_begin,
+      _S_token_bracket_end,
+      _S_token_interval_begin,
+      _S_token_interval_end,
+      _S_token_quoted_class,
+      _S_token_char_class_name,
+      _S_token_collsymbol,
+      _S_token_equiv_class_name,
+      _S_token_opt,
+      _S_token_or,
+      _S_token_closure0,
+      _S_token_closure1,
+      _S_token_ungreedy,
+      _S_token_line_begin,
+      _S_token_line_end,
+      _S_token_word_bound, // neg if _M_value[0] == 'n'
+      _S_token_comma,
+      _S_token_dup_count,
+      _S_token_eof,
+      _S_token_unknown
+    };
+
+  protected:
+    typedef regex_constants::syntax_option_type _FlagT;
+
+    enum _StateT
+    {
+      _S_state_normal,
+      _S_state_in_brace,
+      _S_state_in_bracket,
+    };
+
+  protected:
+    _ScannerBase(_FlagT __flags)
+    : _M_state(_S_state_normal),
+    _M_flags(__flags),
+    _M_escape_tbl(_M_is_ecma()
+		  ? _M_ecma_escape_tbl
+		  : _M_awk_escape_tbl),
+    _M_spec_char(_M_is_ecma()
+		 ? _M_ecma_spec_char
+		 : _M_is_basic()
+		 ? _M_basic_spec_char
+		 : _M_extended_spec_char),
+    _M_at_bracket_start(false)
+    { }
+
+  protected:
+    const char*
+    _M_find_escape(char __c)
+    {
+      auto __it = _M_escape_tbl;
+      for (; __it->first != '\0'; ++__it)
+	if (__it->first == __c)
+	  return &__it->second;
+      return nullptr;
+    }
+
+    bool
+    _M_is_ecma() const
+    { return _M_flags & regex_constants::ECMAScript; }
+
+    bool
+    _M_is_basic() const
+    { return _M_flags & (regex_constants::basic | regex_constants::grep); }
+
+    bool
+    _M_is_extended() const
+    {
+      return _M_flags & (regex_constants::extended
+			 | regex_constants::egrep
+			 | regex_constants::awk);
+    }
+
+    bool
+    _M_is_grep() const
+    { return _M_flags & (regex_constants::grep | regex_constants::egrep); }
+
+    bool
+    _M_is_awk() const
+    { return _M_flags & regex_constants::awk; }
+
+  protected:
+    _StateT                       _M_state;
+    _FlagT                        _M_flags;
+    _TokenT                       _M_token;
+    const std::pair<char, char>*  _M_escape_tbl;
+    const char*                   _M_spec_char;
+    bool                          _M_at_bracket_start;
+
+    const static std::pair<char, _TokenT> _M_token_tbl[];
+    const static std::pair<char, char>    _M_ecma_escape_tbl[];
+    const static std::pair<char, char>    _M_awk_escape_tbl[];
+    const static char                     _M_ecma_spec_char[];
+    const static char                     _M_basic_spec_char[];
+    const static char                     _M_extended_spec_char[];
+  };
+
   /**
    * @brief struct _Scanner. Scans an input range for regex tokens.
    *
@@ -49,51 +163,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    * constructor: different regular expression grammars will interpret
    * the same input pattern in syntactically different ways.
    */
-  template<typename _FwdIter>
+  template<typename _CharT>
     class _Scanner
+    : public _ScannerBase
     {
     public:
-      typedef typename std::iterator_traits<_FwdIter>::value_type _CharT;
+      typedef const _CharT*                                       _IterT;
       typedef std::basic_string<_CharT>                           _StringT;
       typedef regex_constants::syntax_option_type                 _FlagT;
       typedef const std::ctype<_CharT>                            _CtypeT;
 
-      /// Token types returned from the scanner.
-      enum _TokenT
-      {
-	_S_token_anychar,
-	_S_token_ord_char,
-	_S_token_oct_num,
-	_S_token_hex_num,
-	_S_token_backref,
-	_S_token_subexpr_begin,
-	_S_token_subexpr_no_group_begin,
-	_S_token_subexpr_lookahead_begin, // neg if _M_value[0] == 'n'
-	_S_token_subexpr_end,
-	_S_token_bracket_begin,
-	_S_token_bracket_neg_begin,
-	_S_token_bracket_end,
-	_S_token_interval_begin,
-	_S_token_interval_end,
-	_S_token_quoted_class,
-	_S_token_char_class_name,
-	_S_token_collsymbol,
-	_S_token_equiv_class_name,
-	_S_token_opt,
-	_S_token_or,
-	_S_token_closure0,
-	_S_token_closure1,
-	_S_token_ungreedy,
-	_S_token_line_begin,
-	_S_token_line_end,
-	_S_token_word_bound, // neg if _M_value[0] == 'n'
-	_S_token_comma,
-	_S_token_dup_count,
-	_S_token_eof,
-	_S_token_unknown
-      };
-
-      _Scanner(_FwdIter __begin, _FwdIter __end,
+      _Scanner(_IterT __begin, _IterT __end,
 	       _FlagT __flags, std::locale __loc);
 
       void
@@ -113,13 +193,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
     private:
-      enum _StateT
-      {
-	_S_state_normal,
-	_S_state_in_brace,
-	_S_state_in_bracket,
-      };
-
       void
       _M_scan_normal();
 
@@ -141,49 +214,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       _M_eat_class(char);
 
-      constexpr bool
-      _M_is_ecma()
-      { return _M_flags & regex_constants::ECMAScript; }
-
-      constexpr bool
-      _M_is_basic()
-      { return _M_flags & (regex_constants::basic | regex_constants::grep); }
-
-      constexpr bool
-      _M_is_extended()
-      {
-	return _M_flags & (regex_constants::extended
-			   | regex_constants::egrep
-			   | regex_constants::awk);
-      }
-
-      constexpr bool
-      _M_is_grep()
-      { return _M_flags & (regex_constants::grep | regex_constants::egrep); }
-
-      constexpr bool
-      _M_is_awk()
-      { return _M_flags & regex_constants::awk; }
-
-      _StateT                       _M_state;
-      _FwdIter                      _M_current;
-      _FwdIter                      _M_end;
-      _FlagT                        _M_flags;
+      _IterT                        _M_current;
+      _IterT                        _M_end;
       _CtypeT&                      _M_ctype;
-      _TokenT                       _M_token;
       _StringT                      _M_value;
-      bool                          _M_at_bracket_start;
-    public:
-      // FIXME: make them static when this file is stable.
-      const std::map<char, _TokenT> _M_token_map;
-      const std::map<char, char>    _M_ecma_escape_map;
-      const std::map<char, char>    _M_awk_escape_map;
-      const std::set<char>          _M_ecma_spec_char;
-      const std::set<char>          _M_basic_spec_char;
-      const std::set<char>          _M_extended_spec_char;
-
-      const std::map<char, char>&   _M_escape_map;
-      const std::set<char>&         _M_spec_char;
       void (_Scanner::* _M_eat_escape)();
     };
 
diff --git a/libstdc++-v3/include/bits/regex_scanner.tcc b/libstdc++-v3/include/bits/regex_scanner.tcc
index 34d78ec..729a41a 100644
--- a/libstdc++-v3/include/bits/regex_scanner.tcc
+++ b/libstdc++-v3/include/bits/regex_scanner.tcc
@@ -52,106 +52,22 @@ namespace __detail
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-  template<typename _FwdIter>
-    _Scanner<_FwdIter>::
-    _Scanner(_FwdIter __begin, _FwdIter __end,
+  template<typename _CharT>
+    _Scanner<_CharT>::
+    _Scanner(typename _Scanner::_IterT __begin,
+	     typename _Scanner::_IterT __end,
 	     _FlagT __flags, std::locale __loc)
-    : _M_state(_S_state_normal), _M_current(__begin), _M_end(__end),
-      _M_flags(__flags),
+    : _ScannerBase(__flags),
+      _M_current(__begin), _M_end(__end),
       _M_ctype(std::use_facet<_CtypeT>(__loc)),
-      _M_at_bracket_start(false),
-      _M_token_map
-	{
-	  {'^', _S_token_line_begin},
-	  {'$', _S_token_line_end},
-	  {'.', _S_token_anychar},
-	  {'*', _S_token_closure0},
-	  {'+', _S_token_closure1},
-	  {'?', _S_token_opt},
-	  {'|', _S_token_or},
-	  // grep and egrep
-	  {'\n', _S_token_or},
-	},
-      _M_ecma_escape_map
-	{
-	  {'0', '\0'},
-	  {'b', '\b'},
-	  {'f', '\f'},
-	  {'n', '\n'},
-	  {'r', '\r'},
-	  {'t', '\t'},
-	  {'v', '\v'},
-	},
-      _M_awk_escape_map
-	{
-	  {'"', '"'},
-	  {'/', '/'},
-	  {'\\', '\\'},
-	  {'a', '\a'},
-	  {'b', '\b'},
-	  {'f', '\f'},
-	  {'n', '\n'},
-	  {'r', '\r'},
-	  {'t', '\t'},
-	  {'v', '\v'},
-	},
-      _M_ecma_spec_char
-	{
-	  '^',
-	  '$',
-	  '\\',
-	  '.',
-	  '*',
-	  '+',
-	  '?',
-	  '(',
-	  ')',
-	  '[',
-	  ']',
-	  '{',
-	  '}',
-	  '|',
-	},
-      _M_basic_spec_char
-	{
-	  '.',
-	  '[',
-	  '\\',
-	  '*',
-	  '^',
-	  '$',
-	},
-      _M_extended_spec_char
-	{
-	  '.',
-	  '[',
-	  '\\',
-	  '(',
-	  ')',
-	  '*',
-	  '+',
-	  '?',
-	  '{',
-	  '|',
-	  '^',
-	  '$',
-	},
-      _M_escape_map(_M_is_ecma()
-		    ? _M_ecma_escape_map
-		    : _M_awk_escape_map),
-      _M_spec_char(_M_is_ecma()
-		   ? _M_ecma_spec_char
-		   : _M_is_basic()
-		   ? _M_basic_spec_char
-		   : _M_extended_spec_char),
       _M_eat_escape(_M_is_ecma()
 		    ? &_Scanner::_M_eat_escape_ecma
 		    : &_Scanner::_M_eat_escape_posix)
     { _M_advance(); }
 
-  template<typename _FwdIter>
+  template<typename _CharT>
     void
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_advance()
     {
       if (_M_current == _M_end)
@@ -173,9 +89,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Differences between styles:
   // 1) "\(", "\)", "\{" in basic. It's not escaping.
   // 2) "(?:", "(?=", "(?!" in ECMAScript.
-  template<typename _FwdIter>
+  template<typename _CharT>
     void
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_scan_normal()
     {
       auto __c = *_M_current++;
@@ -244,11 +160,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  _M_state = _S_state_in_brace;
 	  _M_token = _S_token_interval_begin;
 	}
-      else if ((_M_spec_char.count(_M_ctype.narrow(__c, '\0'))
+      else if ((*strchrnul(_M_spec_char, _M_ctype.narrow(__c, '\0')) != '\0'
 		&& __c != ']'
 		&& __c != '}')
 	       || (_M_is_grep() && __c == '\n'))
-	_M_token = _M_token_map.at(__c);
+	{
+	  auto __it = _M_token_tbl;
+	  auto __narrowc = _M_ctype.narrow(__c, '\0');
+	  for (; __it->first != '\0'; ++__it)
+	    if (__it->first == __narrowc)
+	      {
+		_M_token = __it->second;
+		return;
+	      }
+	  _GLIBCXX_DEBUG_ASSERT(false);
+	}
       else
 	{
 	  _M_token = _S_token_ord_char;
@@ -259,9 +185,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Differences between styles:
   // 1) different semantics of "[]" and "[^]".
   // 2) Escaping in bracket expr.
-  template<typename _FwdIter>
+  template<typename _CharT>
     void
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_scan_in_bracket()
     {
       if (_M_current == _M_end)
@@ -316,9 +242,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // Differences between styles:
   // 1) "\}" in basic style.
-  template<typename _FwdIter>
+  template<typename _CharT>
     void
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_scan_in_brace()
     {
       if (_M_current == _M_end)
@@ -357,21 +283,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	__throw_regex_error(regex_constants::error_badbrace);
     }
 
-  template<typename _FwdIter>
+  template<typename _CharT>
     void
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_eat_escape_ecma()
     {
       if (_M_current == _M_end)
 	__throw_regex_error(regex_constants::error_escape);
 
       auto __c = *_M_current++;
+      auto __pos = _M_find_escape(_M_ctype.narrow(__c, '\0'));
 
-      if (_M_escape_map.count(_M_ctype.narrow(__c, '\0'))
-	  && (__c != 'b' || _M_state == _S_state_in_bracket))
+      if (__pos != nullptr && (__c != 'b' || _M_state == _S_state_in_bracket))
 	{
 	  _M_token = _S_token_ord_char;
-	  _M_value.assign(1, _M_escape_map.at(__c));
+	  _M_value.assign(1, *__pos);
 	}
       else if (__c == 'b')
 	{
@@ -431,9 +357,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // Differences between styles:
   // 1) Extended doesn't support backref, but basic does.
-  template<typename _FwdIter>
+  template<typename _CharT>
     void
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_eat_escape_posix()
     {
       if (_M_current == _M_end)
@@ -441,7 +367,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       auto __c = *_M_current;
 
-      if (_M_spec_char.count(_M_ctype.narrow(__c, '\0')))
+      if (*strchrnul(_M_spec_char, _M_ctype.narrow(__c, '\0')) != '\0')
 	{
 	  _M_token = _S_token_ord_char;
 	  _M_value.assign(1, __c);
@@ -469,17 +395,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       ++_M_current;
     }
 
-  template<typename _FwdIter>
+  template<typename _CharT>
     void
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_eat_escape_awk()
     {
       auto __c = *_M_current++;
+      auto __pos = _M_find_escape(_M_ctype.narrow(__c, '\0'));
 
-      if (_M_escape_map.count(_M_ctype.narrow(__c, '\0')))
+      if (__pos != nullptr)
 	{
 	  _M_token = _S_token_ord_char;
-	  _M_value.assign(1, _M_escape_map.at(__c));
+	  _M_value.assign(1, *__pos);
 	}
       // \ddd for oct representation
       else if (_M_ctype.is(_CtypeT::digit, __c)
@@ -505,9 +432,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Eats a character class or throwns an exception.
   // __ch cound be ':', '.' or '=', _M_current is the char after ']' when
   // returning.
-  template<typename _FwdIter>
+  template<typename _CharT>
     void
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_eat_class(char __ch)
     {
       for (_M_value.clear(); _M_current != _M_end && *_M_current != __ch;)
@@ -525,9 +452,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
 #ifdef _GLIBCXX_DEBUG
-  template<typename _FwdIter>
+  template<typename _CharT>
     std::ostream&
-    _Scanner<_FwdIter>::
+    _Scanner<_CharT>::
     _M_print(std::ostream& ostr)
     {
       switch (_M_token)
diff --git a/libstdc++-v3/include/std/regex b/libstdc++-v3/include/std/regex
index 9395f50..f8a5d02 100644
--- a/libstdc++-v3/include/std/regex
+++ b/libstdc++-v3/include/std/regex
@@ -53,6 +53,7 @@
 #include <string>
 #include <utility>
 #include <vector>
+#include <cstring>
 
 #include <bits/regex_constants.h>
 #include <bits/regex_error.h>
diff --git a/libstdc++-v3/src/c++11/regex.cc b/libstdc++-v3/src/c++11/regex.cc
index a0ad374..53e828e 100644
--- a/libstdc++-v3/src/c++11/regex.cc
+++ b/libstdc++-v3/src/c++11/regex.cc
@@ -22,11 +22,56 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // <http://www.gnu.org/licenses/>.
 
-#include <stdexcept>
-#include <bits/regex_error.h>
+#include <regex>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+  const std::pair<char, _ScannerBase::_TokenT> _ScannerBase::_M_token_tbl[] =
+      {
+	{'^', _S_token_line_begin},
+	{'$', _S_token_line_end},
+	{'.', _S_token_anychar},
+	{'*', _S_token_closure0},
+	{'+', _S_token_closure1},
+	{'?', _S_token_opt},
+	{'|', _S_token_or},
+	// grep and egrep
+	{'\n', _S_token_or},
+	{'\0', _S_token_or},
+      };
+  const std::pair<char, char>    _ScannerBase::_M_ecma_escape_tbl[] =
+      {
+	{'0', '\0'},
+	{'b', '\b'},
+	{'f', '\f'},
+	{'n', '\n'},
+	{'r', '\r'},
+	{'t', '\t'},
+	{'v', '\v'},
+	{'\0', '\0'},
+      };
+  const std::pair<char, char>    _ScannerBase::_M_awk_escape_tbl[] =
+      {
+	{'"', '"'},
+	{'/', '/'},
+	{'\\', '\\'},
+	{'a', '\a'},
+	{'b', '\b'},
+	{'f', '\f'},
+	{'n', '\n'},
+	{'r', '\r'},
+	{'t', '\t'},
+	{'v', '\v'},
+	{'\0', '\0'},
+      };
+  const char _ScannerBase::_M_ecma_spec_char[] = "^$\\.*+?()[]{}|";
+  const char _ScannerBase::_M_basic_spec_char[] = ".[\\*^$";
+  const char _ScannerBase::_M_extended_spec_char[] = ".[\\()*+?{|^$";
+_GLIBCXX_END_NAMESPACE_VERSION
+}
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   regex_error::regex_error(regex_constants::error_type __ecode)
-------------- next part --------------
commit 3c7f86e569e458a4846bd62b780890ea9f716803
Author: tim <timshen91@gmail.com>
Date:   Fri Jan 10 20:27:32 2014 -0500

    2014-01-11  Tim Shen  <timshen91@gmail.com>
    
    	* include/bits/regex.h (__compile_nfa<>(), basic_regex<>::basic_regex(),
    	basic_regex<>::assign()): Change __compile_nfa to accept
    	const _CharT* only.
    	* include/bits/regex_compiler.h: Change _Compiler's template
    	argument from <_FwdIter, _TraitsT> to <_TraitsT>.
    	* include/bits/regex_compiler.tcc: Likewise.

diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h
index ae8e1f5..816f5cf 100644
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -60,51 +60,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename, typename, typename, bool>
     class _Executor;
 
-  template<typename _Tp>
-    struct __has_contiguous_iter : std::false_type { };
-
-  template<typename _Ch, typename _Tr, typename _Alloc>
-    struct __has_contiguous_iter<std::basic_string<_Ch, _Tr, _Alloc>>
-    : std::true_type  // string<Ch> storage is contiguous
-    { };
-
-  template<typename _Tp, typename _Alloc>
-    struct __has_contiguous_iter<std::vector<_Tp, _Alloc>>
-    : std::true_type  // vector<Tp> storage is contiguous
-    { };
-
-  template<typename _Alloc>
-    struct __has_contiguous_iter<std::vector<bool, _Alloc>>
-    : std::false_type // vector<bool> storage is not contiguous
-    { };
-
-  template<typename _Tp>
-    struct __is_contiguous_normal_iter : std::false_type { };
-
-  template<typename _Tp, typename _Cont>
-    struct
-    __is_contiguous_normal_iter<__gnu_cxx::__normal_iterator<_Tp, _Cont>>
-    : __has_contiguous_iter<_Cont>::type
-    { };
-
-  template<typename _Iter, typename _TraitsT>
-    using __enable_if_contiguous_normal_iter
-      = typename enable_if< __is_contiguous_normal_iter<_Iter>::value,
-			    std::shared_ptr<_NFA<_TraitsT>> >::type;
-
-  template<typename _Iter, typename _TraitsT>
-    using __disable_if_contiguous_normal_iter
-      = typename enable_if< !__is_contiguous_normal_iter<_Iter>::value,
-			    std::shared_ptr<_NFA<_TraitsT>> >::type;
-
-  template<typename _FwdIter, typename _TraitsT>
-    __disable_if_contiguous_normal_iter<_FwdIter, _TraitsT>
-    __compile_nfa(_FwdIter __first, _FwdIter __last, const _TraitsT& __traits,
-		  regex_constants::syntax_option_type __flags);
-
-  template<typename _Iter, typename _TraitsT>
-    __enable_if_contiguous_normal_iter<_Iter, _TraitsT>
-    __compile_nfa(_Iter __first, _Iter __last, const _TraitsT& __traits,
+  template<typename _TraitsT>
+    inline std::shared_ptr<_NFA<_TraitsT>>
+    __compile_nfa(const typename _TraitsT::char_type* __first,
+		  const typename _TraitsT::char_type* __last,
+		  const _TraitsT& __traits,
 		  regex_constants::syntax_option_type __flags);
 
 _GLIBCXX_END_NAMESPACE_VERSION
@@ -561,7 +521,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		    flag_type __f = ECMAScript)
 	: _M_flags(__f),
 	  _M_original_str(__first, __last),
-	  _M_automaton(__detail::__compile_nfa(__first, __last, _M_traits,
+	  _M_automaton(__detail::__compile_nfa(_M_original_str.c_str(),
+					       _M_original_str.c_str()
+						 + _M_original_str.size(),
+					       _M_traits,
 					       _M_flags))
 	{ }
 
@@ -698,7 +661,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	{
 	  _M_flags = __flags;
 	  _M_original_str.assign(__s.begin(), __s.end());
-	  _M_automaton = __detail::__compile_nfa(__s.begin(), __s.end(),
+	  auto __p = _M_original_str.c_str();
+	  _M_automaton = __detail::__compile_nfa(__p,
+						 __p + _M_original_str.size(),
 						 _M_traits, _M_flags);
 	  return *this;
 	}
diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h
index e692726..6c237f5 100644
--- a/libstdc++-v3/include/bits/regex_compiler.h
+++ b/libstdc++-v3/include/bits/regex_compiler.h
@@ -43,15 +43,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct _BracketMatcher;
 
   /// Builds an NFA from an input iterator interval.
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     class _Compiler
     {
     public:
-      typedef typename _TraitsT::string_type      _StringT;
+      typedef typename _TraitsT::char_type        _CharT;
+      typedef const _CharT*                       _IterT;
       typedef _NFA<_TraitsT>              	  _RegexT;
       typedef regex_constants::syntax_option_type _FlagT;
 
-      _Compiler(_FwdIter __b, _FwdIter __e,
+      _Compiler(_IterT __b, _IterT __e,
 		const _TraitsT& __traits, _FlagT __flags);
 
       std::shared_ptr<_RegexT>
@@ -59,11 +60,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return make_shared<_RegexT>(std::move(_M_nfa)); }
 
     private:
-      typedef _Scanner<typename _TraitsT::char_type>          _ScannerT;
+      typedef _Scanner<_CharT>                                _ScannerT;
+      typedef typename _TraitsT::string_type                  _StringT;
       typedef typename _ScannerT::_TokenT                     _TokenT;
       typedef _StateSeq<_TraitsT>                     	      _StateSeqT;
       typedef std::stack<_StateSeqT, std::vector<_StateSeqT>> _StackT;
-      typedef std::ctype<typename _TraitsT::char_type>        _CtypeT;
+      typedef std::ctype<_CharT>                              _CtypeT;
 
       // accepts a specific token or returns false.
       bool
@@ -138,25 +140,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _StackT         _M_stack;
     };
 
-  template<typename _FwdIter, typename _TraitsT>
-    inline __disable_if_contiguous_normal_iter<_FwdIter, _TraitsT>
-    __compile_nfa(_FwdIter __first, _FwdIter __last, const _TraitsT& __traits,
+  template<typename _TraitsT>
+    inline std::shared_ptr<_NFA<_TraitsT>>
+    __compile_nfa(const typename _TraitsT::char_type* __first,
+		  const typename _TraitsT::char_type* __last,
+		  const _TraitsT& __traits,
 		  regex_constants::syntax_option_type __flags)
     {
-      using _Cmplr = _Compiler<_FwdIter, _TraitsT>;
+      using _Cmplr = _Compiler<_TraitsT>;
       return _Cmplr(__first, __last, __traits, __flags)._M_get_nfa();
     }
 
-  template<typename _Iter, typename _TraitsT>
-    inline __enable_if_contiguous_normal_iter<_Iter, _TraitsT>
-    __compile_nfa(_Iter __first, _Iter __last, const _TraitsT& __traits,
-		  regex_constants::syntax_option_type __flags)
-    {
-      size_t __len = __last - __first;
-      const auto* __cfirst = __len ? std::__addressof(*__first) : nullptr;
-      return __compile_nfa(__cfirst, __cfirst + __len, __traits, __flags);
-    }
-
   // [28.13.14]
   template<typename _TraitsT, bool __icase, bool __collate>
     class _RegexTranslator
diff --git a/libstdc++-v3/include/bits/regex_compiler.tcc b/libstdc++-v3/include/bits/regex_compiler.tcc
index 9ff538d..34336cc 100644
--- a/libstdc++-v3/include/bits/regex_compiler.tcc
+++ b/libstdc++-v3/include/bits/regex_compiler.tcc
@@ -59,9 +59,9 @@ namespace __detail
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-  template<typename _FwdIter, typename _TraitsT>
-    _Compiler<_FwdIter, _TraitsT>::
-    _Compiler(_FwdIter __b, _FwdIter __e,
+  template<typename _TraitsT>
+    _Compiler<_TraitsT>::
+    _Compiler(_IterT __b, _IterT __e,
 	      const _TraitsT& __traits, _FlagT __flags)
     : _M_flags((__flags
 		& (regex_constants::ECMAScript
@@ -89,9 +89,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _M_nfa._M_eliminate_dummy();
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_disjunction()
     {
       this->_M_alternative();
@@ -110,9 +110,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_alternative()
     {
       if (this->_M_term())
@@ -126,9 +126,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	_M_stack.push(_StateSeqT(_M_nfa, _M_nfa._M_insert_dummy()));
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     bool
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_term()
     {
       if (this->_M_assertion())
@@ -141,9 +141,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return false;
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     bool
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_assertion()
     {
       if (_M_match_token(_ScannerT::_S_token_line_begin))
@@ -172,9 +172,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return true;
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_quantifier()
     {
       bool __neg = (_M_flags & regex_constants::ECMAScript);
@@ -292,9 +292,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	      __func<true, true>(args);\
 	while (false)
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     bool
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_atom()
     {
       if (_M_match_token(_ScannerT::_S_token_anychar))
@@ -335,9 +335,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return true;
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     bool
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_bracket_expression()
     {
       bool __neg =
@@ -349,10 +349,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 #undef __INSERT_REGEX_MATCHER
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
   template<bool __icase, bool __collate>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_insert_any_matcher_ecma()
     {
       _M_stack.push(_StateSeqT(_M_nfa,
@@ -361,10 +361,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    (_M_traits))));
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
   template<bool __icase, bool __collate>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_insert_any_matcher_posix()
     {
       _M_stack.push(_StateSeqT(_M_nfa,
@@ -373,10 +373,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    (_M_traits))));
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
   template<bool __icase, bool __collate>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_insert_char_matcher()
     {
       _M_stack.push(_StateSeqT(_M_nfa,
@@ -385,10 +385,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    (_M_value[0], _M_traits))));
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
   template<bool __icase, bool __collate>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_insert_character_class_matcher()
     {
       _GLIBCXX_DEBUG_ASSERT(_M_value.size() == 1);
@@ -400,10 +400,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	_M_nfa._M_insert_matcher(std::move(__matcher))));
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
   template<bool __icase, bool __collate>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_insert_bracket_matcher(bool __neg)
     {
       _BracketMatcher<_TraitsT, __icase, __collate> __matcher(__neg, _M_traits);
@@ -414,10 +414,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 			       _M_nfa._M_insert_matcher(std::move(__matcher))));
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
   template<bool __icase, bool __collate>
     void
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_expression_term(_BracketMatcher<_TraitsT, __icase, __collate>& __matcher)
     {
       if (_M_match_token(_ScannerT::_S_token_collsymbol))
@@ -452,9 +452,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	__throw_regex_error(regex_constants::error_brack);
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     bool
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_try_char()
     {
       bool __is_char = false;
@@ -473,9 +473,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return __is_char;
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     bool
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_match_token(_TokenT token)
     {
       if (token == _M_scanner._M_get_token())
@@ -487,9 +487,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return false;
     }
 
-  template<typename _FwdIter, typename _TraitsT>
+  template<typename _TraitsT>
     int
-    _Compiler<_FwdIter, _TraitsT>::
+    _Compiler<_TraitsT>::
     _M_cur_int_value(int __radix)
     {
       long __v = 0;
-------------- next part --------------
commit 5f91f2d3cffcf109547c97df549236746300f6fe
Author: tim <timshen91@gmail.com>
Date:   Fri Jan 10 22:20:41 2014 -0500

    2014-01-11  Tim Shen  <timshen91@gmail.com>
    
    	* include/bits/regex_automaton.tcc (_StateSeq<>::_M_clone()): Do not
    	use std::map.
    	* include/bits/regex_automaton.h: Do not use std::set.
    	* include/bits/regex_compiler.h (_BracketMatcher<>::_M_add_char(),
    	_BracketMatcher<>::_M_add_collating_element(),
    	_BracketMatcher<>::_M_add_equivalence_class(),
    	_BracketMatcher<>::_M_make_range()): Likewise.
    	* include/bits/regex_compiler.tcc (_BracketMatcher<>::_M_apply()):
    	Likewise.
    	* include/bits/regex_executor.h: Do not use std::queue.
    	* include/bits/regex_executor.tcc (_Executor<>::_M_main(),
    	_Executor<>::_M_dfs()): Likewise.
    	* include/std/regex: Remove <map>, <set> and <queue>.

diff --git a/libstdc++-v3/include/bits/regex_automaton.h b/libstdc++-v3/include/bits/regex_automaton.h
index ea73675..a442cfe 100644
--- a/libstdc++-v3/include/bits/regex_automaton.h
+++ b/libstdc++-v3/include/bits/regex_automaton.h
@@ -41,7 +41,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    */
 
   typedef long _StateIdT;
-  typedef std::set<_StateIdT> _StateSet;
   static const _StateIdT _S_invalid_state_id  = -1;
 
   template<typename _CharT>
@@ -138,16 +137,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _M_start() const
     { return _M_start_state; }
 
-    const _StateSet&
-    _M_final_states() const
-    { return _M_accepting_states; }
-
     _SizeT
     _M_sub_count() const
     { return _M_subexpr_count; }
 
     std::vector<size_t>       _M_paren_stack;
-    _StateSet                 _M_accepting_states;
     _FlagT                    _M_flags;
     _StateIdT                 _M_start_state;
     _SizeT                    _M_subexpr_count;
@@ -172,7 +166,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _M_insert_accept()
       {
 	auto __ret = _M_insert_state(_StateT(_S_opcode_accept));
-	this->_M_accepting_states.insert(__ret);
 	return __ret;
       }
 
diff --git a/libstdc++-v3/include/bits/regex_automaton.tcc b/libstdc++-v3/include/bits/regex_automaton.tcc
index e222803..759b053 100644
--- a/libstdc++-v3/include/bits/regex_automaton.tcc
+++ b/libstdc++-v3/include/bits/regex_automaton.tcc
@@ -186,7 +186,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _StateSeq<_TraitsT>
     _StateSeq<_TraitsT>::_M_clone()
     {
-      std::map<_StateIdT, _StateIdT> __m;
+      std::vector<_StateIdT> __m(_M_nfa.size(), -1);
       std::stack<_StateIdT> __stack;
       __stack.push(_M_start);
       while (!__stack.empty())
@@ -194,30 +194,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  auto __u = __stack.top();
 	  __stack.pop();
 	  auto __dup = _M_nfa[__u];
+	  // _M_insert_state() never return -1
 	  auto __id = _M_nfa._M_insert_state(__dup);
 	  __m[__u] = __id;
 	  if (__u == _M_end)
 	    continue;
-	  if (__m.count(__dup._M_next) == 0)
+	  if (__dup._M_next != _S_invalid_state_id && __m[__dup._M_next] == -1)
 	    __stack.push(__dup._M_next);
 	  if (__dup._M_opcode == _S_opcode_alternative
 	      || __dup._M_opcode == _S_opcode_subexpr_lookahead)
-	    if (__m.count(__dup._M_alt) == 0)
+	    if (__dup._M_alt != _S_invalid_state_id && __m[__dup._M_alt] == -1)
 	      __stack.push(__dup._M_alt);
 	}
-      for (auto __it : __m)
+      long __size = static_cast<long>(__m.size());
+      for (long __k = 0; __k < __size; __k++)
 	{
-	  auto& __ref = _M_nfa[__it.second];
-	  if (__ref._M_next != -1)
+	  long __v;
+	  if ((__v = __m[__k]) == -1)
+	    continue;
+	  auto& __ref = _M_nfa[__v];
+	  if (__ref._M_next != _S_invalid_state_id)
 	    {
-	      _GLIBCXX_DEBUG_ASSERT(__m.count(__ref._M_next));
+	      _GLIBCXX_DEBUG_ASSERT(__m[__ref._M_next] != -1);
 	      __ref._M_next = __m[__ref._M_next];
 	    }
 	  if (__ref._M_opcode == _S_opcode_alternative
 	      || __ref._M_opcode == _S_opcode_subexpr_lookahead)
-	    if (__ref._M_alt != -1)
+	    if (__ref._M_alt != _S_invalid_state_id)
 	      {
-		_GLIBCXX_DEBUG_ASSERT(__m.count(__ref._M_alt));
+		_GLIBCXX_DEBUG_ASSERT(__m[__ref._M_alt] != -1);
 		__ref._M_alt = __m[__ref._M_alt];
 	      }
 	}
diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h
index 6c237f5..216f8fb 100644
--- a/libstdc++-v3/include/bits/regex_compiler.h
+++ b/libstdc++-v3/include/bits/regex_compiler.h
@@ -60,12 +60,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return make_shared<_RegexT>(std::move(_M_nfa)); }
 
     private:
-      typedef _Scanner<_CharT>                                _ScannerT;
-      typedef typename _TraitsT::string_type                  _StringT;
-      typedef typename _ScannerT::_TokenT                     _TokenT;
-      typedef _StateSeq<_TraitsT>                     	      _StateSeqT;
-      typedef std::stack<_StateSeqT, std::vector<_StateSeqT>> _StackT;
-      typedef std::ctype<_CharT>                              _CtypeT;
+      typedef _Scanner<_CharT>               _ScannerT;
+      typedef typename _TraitsT::string_type _StringT;
+      typedef typename _ScannerT::_TokenT    _TokenT;
+      typedef _StateSeq<_TraitsT>            _StateSeqT;
+      typedef std::stack<_StateSeqT>         _StackT;
+      typedef std::ctype<_CharT>             _CtypeT;
 
       // accepts a specific token or returns false.
       bool
@@ -301,9 +301,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     };
 
   /// Matches a character range (bracket expression)
-  // TODO: Convert used _M_flags fields to template parameters, including
-  // collate and icase. Avoid using std::set, could use flat_set
-  // (sorted vector and binary search) instead.
   template<typename _TraitsT, bool __icase, bool __collate>
     struct _BracketMatcher
     {
@@ -334,7 +331,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       _M_add_char(_CharT __c)
       {
-	_M_char_set.insert(_M_translator._M_translate(__c));
+	_M_char_set.push_back(_M_translator._M_translate(__c));
 #ifdef _GLIBCXX_DEBUG
 	_M_is_ready = false;
 #endif
@@ -347,7 +344,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 						 __s.data() + __s.size());
 	if (__st.empty())
 	  __throw_regex_error(regex_constants::error_collate);
-	_M_char_set.insert(_M_translator._M_translate(__st[0]));
+	_M_char_set.push_back(_M_translator._M_translate(__st[0]));
 #ifdef _GLIBCXX_DEBUG
 	_M_is_ready = false;
 #endif
@@ -362,7 +359,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  __throw_regex_error(regex_constants::error_collate);
 	__st = _M_traits.transform_primary(__st.data(),
 					   __st.data() + __st.size());
-	_M_equiv_set.insert(__st);
+	_M_equiv_set.push_back(__st);
 #ifdef _GLIBCXX_DEBUG
 	_M_is_ready = false;
 #endif
@@ -385,7 +382,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       _M_make_range(_CharT __l, _CharT __r)
       {
-	_M_range_set.insert(make_pair(_M_translator._M_transform(__l),
+	_M_range_set.push_back(make_pair(_M_translator._M_transform(__l),
 				      _M_translator._M_transform(__r)));
 #ifdef _GLIBCXX_DEBUG
 	_M_is_ready = false;
@@ -430,16 +427,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { }
 
     private:
-      _CacheT                                _M_cache;
-      std::set<_CharT>                       _M_char_set;
-      std::set<_StringT>                     _M_equiv_set;
-      std::set<pair<_StrTransT, _StrTransT>> _M_range_set;
-      _CharClassT                            _M_class_set;
-      _TransT                                _M_translator;
-      const _TraitsT&                        _M_traits;
-      bool                                   _M_is_non_matching;
+      _CacheT                                   _M_cache;
+      std::vector<_CharT>                       _M_char_set;
+      std::vector<_StringT>                     _M_equiv_set;
+      std::vector<pair<_StrTransT, _StrTransT>> _M_range_set;
+      _CharClassT                               _M_class_set;
+      _TransT                                   _M_translator;
+      const _TraitsT&                           _M_traits;
+      bool                                      _M_is_non_matching;
 #ifdef _GLIBCXX_DEBUG
-      bool                                   _M_is_ready;
+      bool                                      _M_is_ready;
 #endif
     };
 
diff --git a/libstdc++-v3/include/bits/regex_compiler.tcc b/libstdc++-v3/include/bits/regex_compiler.tcc
index 34336cc..621e43f 100644
--- a/libstdc++-v3/include/bits/regex_compiler.tcc
+++ b/libstdc++-v3/include/bits/regex_compiler.tcc
@@ -505,7 +505,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _M_apply(_CharT __ch, false_type) const
     {
       bool __ret = false;
-      if (_M_char_set.count(_M_translator._M_translate(__ch)))
+      if (std::find(_M_char_set.begin(), _M_char_set.end(),
+		    _M_translator._M_translate(__ch))
+	  != _M_char_set.end())
 	__ret = true;
       else
 	{
@@ -518,8 +520,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	      }
 	  if (_M_traits.isctype(__ch, _M_class_set))
 	    __ret = true;
-	  else if (_M_equiv_set.count(_M_traits.
-				      transform_primary(&__ch, &__ch+1)))
+	  else if (std::find(_M_equiv_set.begin(), _M_equiv_set.end(),
+			     _M_traits.transform_primary(&__ch, &__ch+1))
+		   != _M_equiv_set.end())
 	    __ret = true;
 	}
       if (_M_is_non_matching)
diff --git a/libstdc++-v3/include/bits/regex_executor.h b/libstdc++-v3/include/bits/regex_executor.h
index bed9014..0885716 100644
--- a/libstdc++-v3/include/bits/regex_executor.h
+++ b/libstdc++-v3/include/bits/regex_executor.h
@@ -65,7 +65,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _M_nfa(*__re._M_automaton),
       _M_results(__results),
       _M_match_queue(__dfs_mode ? nullptr
-		     : new queue<pair<_StateIdT, _ResultsVec>>()),
+		     : new vector<pair<_StateIdT, _ResultsVec>>()),
       _M_visited(__dfs_mode ? nullptr : new vector<bool>(_M_nfa.size())),
       _M_flags((__flags & regex_constants::match_prev_avail)
 	       ? (__flags
@@ -133,23 +133,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _M_lookahead(_State<_TraitsT> __state);
 
     public:
-      _ResultsVec                                          _M_cur_results;
-      _BiIter                                              _M_current;
-      const _BiIter                                        _M_begin;
-      const _BiIter                                        _M_end;
-      const _RegexT&                                       _M_re;
-      const _NFAT&                                         _M_nfa;
-      _ResultsVec&                                         _M_results;
+      _ResultsVec                                           _M_cur_results;
+      _BiIter                                               _M_current;
+      const _BiIter                                         _M_begin;
+      const _BiIter                                         _M_end;
+      const _RegexT&                                        _M_re;
+      const _NFAT&                                          _M_nfa;
+      _ResultsVec&                                          _M_results;
       // Used in BFS, saving states that need to be considered for the next
       // character.
-      std::unique_ptr<queue<pair<_StateIdT, _ResultsVec>>> _M_match_queue;
+      std::unique_ptr<vector<pair<_StateIdT, _ResultsVec>>> _M_match_queue;
       // Used in BFS, indicating that which state is already visited.
-      std::unique_ptr<vector<bool>>                        _M_visited;
-      _FlagT                                               _M_flags;
+      std::unique_ptr<vector<bool>>                         _M_visited;
+      _FlagT                                                _M_flags;
       // To record current solution.
-      _StateIdT                                            _M_start_state;
+      _StateIdT                                             _M_start_state;
       // Do we have a solution so far?
-      bool                                                 _M_has_sol;
+      bool                                                  _M_has_sol;
     };
 
  //@} regex-detail
diff --git a/libstdc++-v3/include/bits/regex_executor.tcc b/libstdc++-v3/include/bits/regex_executor.tcc
index 85b70b8..e1cfcb0 100644
--- a/libstdc++-v3/include/bits/regex_executor.tcc
+++ b/libstdc++-v3/include/bits/regex_executor.tcc
@@ -111,7 +111,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
       else
 	{
-	  _M_match_queue->push(make_pair(_M_start_state, _M_results));
+	  _M_match_queue->push_back(make_pair(_M_start_state, _M_results));
 	  bool __ret = false;
 	  while (1)
 	    {
@@ -120,10 +120,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		break;
 	      _M_visited->assign(_M_visited->size(), false);
 	      auto _M_old_queue = std::move(*_M_match_queue);
-	      while (!_M_old_queue.empty())
+	      for (auto __task : _M_old_queue)
 		{
-		  auto __task = _M_old_queue.front();
-		  _M_old_queue.pop();
 		  _M_cur_results = __task.second;
 		  _M_dfs<__match_mode>(__task.first);
 		}
@@ -279,7 +277,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    }
 	  else
 	    if (__state._M_matches(*_M_current))
-	      _M_match_queue->push(make_pair(__state._M_next, _M_cur_results));
+	      _M_match_queue->push_back(make_pair(__state._M_next,
+						  _M_cur_results));
 	  break;
 	// First fetch the matched result from _M_cur_results as __submatch;
 	// then compare it with
diff --git a/libstdc++-v3/include/std/regex b/libstdc++-v3/include/std/regex
index f8a5d02..9161f48 100644
--- a/libstdc++-v3/include/std/regex
+++ b/libstdc++-v3/include/std/regex
@@ -44,9 +44,6 @@
 #include <iterator>
 #include <locale>
 #include <memory>
-#include <map>
-#include <queue>
-#include <set>
 #include <sstream>
 #include <stack>
 #include <stdexcept>
-------------- next part --------------
commit d3432ea66518c90347f20146f5b700ec7cd4ee80
Author: tim <timshen91@gmail.com>
Date:   Sat Jan 11 15:03:19 2014 -0500

    2014-01-11  Tim Shen  <timshen91@gmail.com>
    
    	* config/abi/pre/gnu.ver: Export _Compiler.
    	* include/bits/regex.h (basic_regex<>::basic_regex()): Remove `const`
    	of rvalue reference.
    	* include/bits/regex_compiler.tcc: Add extern template class _Compiler.
    	* src/c++11/Makefile.am: Add regex-inst.cc
    	* src/c++11/Makefile.in: Regenerate.
    	* src/c++11/regex-inst.cc: Instantiate _Compiler.

diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 147b11b..7f1ae9f 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -1374,6 +1374,21 @@ GLIBCXX_3.4.20 {
     # std::__detail::_ScannerBase::*
     _ZNSt8__detail12_ScannerBase*;
 
+    # std::__detail::_Compiler::*
+    _ZNSt8__detail9_CompilerISt12regex_traitsI[cw]*;
+
+    # std::vector<string>
+    _ZNSt6vectorISsSaISsEED2Ev;
+    _ZNSt6vectorISsSaISsEED1Ev;
+    _ZNSt6vectorISsSaISsEEC2ERKS1_;
+    _ZNSt6vectorISsSaISsEEC1ERKS1_;
+
+    # std::vector<wstring>
+    _ZNSt6vectorISbIwSt11char_traitsIwESaIwEESaIS3_EEC2ERKS5_;
+    _ZNSt6vectorISbIwSt11char_traitsIwESaIwEESaIS3_EED2Ev;
+    _ZNSt6vectorISbIwSt11char_traitsIwESaIwEESaIS3_EED1Ev;
+    _ZNSt6vectorISbIwSt11char_traitsIwESaIwEESaIS3_EEC1ERKS5_;
+
 } GLIBCXX_3.4.19;
 
 # Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/src/c++11/Makefile.am b/libstdc++-v3/src/c++11/Makefile.am
index cf1e3be..cf6c2b6 100644
--- a/libstdc++-v3/src/c++11/Makefile.am
+++ b/libstdc++-v3/src/c++11/Makefile.am
@@ -41,6 +41,7 @@ sources = \
 	placeholders.cc \
 	random.cc \
 	regex.cc  \
+	regex-inst.cc \
 	shared_ptr.cc \
 	snprintf_lite.cc \
 	system_error.cc \
@@ -68,6 +69,13 @@ hashtable_c++0x.lo: hashtable_c++0x.cc
 hashtable_c++0x.o: hashtable_c++0x.cc
 	$(CXXCOMPILE) -fimplicit-templates -c $<
 
+# Use special rules for the regex-inst.cc file so that all
+# the generated template functions are also instantiated.
+regex-inst.lo: regex-inst.cc
+	$(LTCXXCOMPILE) -fimplicit-templates -c $<
+regex-inst.o: regex-inst.cc
+	$(CXXCOMPILE) -fimplicit-templates -c $<
+
 # AM_CXXFLAGS needs to be in each subdirectory so that it can be
 # modified in a per-library or per-sub-library way.  Need to manually
 # set this option because CONFIG_CXXFLAGS has to be after
diff --git a/libstdc++-v3/src/c++11/Makefile.in b/libstdc++-v3/src/c++11/Makefile.in
index 83b7bd1..772dd27 100644
--- a/libstdc++-v3/src/c++11/Makefile.in
+++ b/libstdc++-v3/src/c++11/Makefile.in
@@ -70,8 +70,8 @@ libc__11convenience_la_LIBADD =
 am__objects_1 = chrono.lo condition_variable.lo debug.lo \
 	functexcept.lo functional.lo future.lo hash_c++0x.lo \
 	hashtable_c++0x.lo limits.lo mutex.lo placeholders.lo \
-	random.lo regex.lo shared_ptr.lo snprintf_lite.lo \
-	system_error.lo thread.lo
+	random.lo regex.lo regex-inst.lo shared_ptr.lo \
+	snprintf_lite.lo system_error.lo thread.lo
 @ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = fstream-inst.lo \
 @ENABLE_EXTERN_TEMPLATE_TRUE@	string-inst.lo wstring-inst.lo
 am_libc__11convenience_la_OBJECTS = $(am__objects_1) $(am__objects_2)
@@ -324,6 +324,7 @@ sources = \
 	placeholders.cc \
 	random.cc \
 	regex.cc  \
+	regex-inst.cc \
 	shared_ptr.cc \
 	snprintf_lite.cc \
 	system_error.cc \
@@ -643,6 +644,13 @@ hashtable_c++0x.lo: hashtable_c++0x.cc
 hashtable_c++0x.o: hashtable_c++0x.cc
 	$(CXXCOMPILE) -fimplicit-templates -c $<
 
+# Use special rules for the regex-inst.cc file so that all
+# the generated template functions are also instantiated.
+regex-inst.lo: regex-inst.cc
+	$(LTCXXCOMPILE) -fimplicit-templates -c $<
+regex-inst.o: regex-inst.cc
+	$(CXXCOMPILE) -fimplicit-templates -c $<
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git a/libstdc++-v3/src/c++11/regex-inst.cc b/libstdc++-v3/src/c++11/regex-inst.cc
new file mode 100644
index 0000000..3712092
--- /dev/null
+++ b/libstdc++-v3/src/c++11/regex-inst.cc
@@ -0,0 +1,38 @@
+// regex -*- C++ -*-
+
+// Copyright (C) 2011-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+#include <regex>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  template class _Compiler<regex_traits<char>>;
+  template class _Compiler<regex_traits<wchar_t>>;
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace __detail
+} // namespace std


More information about the Libstdc++ mailing list