diff mbox

Patch set for regex instantiation

Message ID 20140629171801.GR2711@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely June 29, 2014, 5:18 p.m. UTC
On 11/01/14 19:48 -0500, Tim Shen wrote:
>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.

I think it might be time to revisit this change and put the data
members of _ScannerBase into the .so, as we're creating and
initializing 136 bytes of duplicated constants every time we construct
a std::regex.

Alternatively, we could just make them local statics instead of member
data and still remove the duplciation (see attached).

Comments

Tim Shen June 29, 2014, 6:47 p.m. UTC | #1
On Sun, Jun 29, 2014 at 10:18 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> Alternatively, we could just make them local statics instead of member
> data and still remove the duplciation (see attached).

This is a good idea. Can we use constexpr for the functions/static variables?
Daniel Krügler June 29, 2014, 8:33 p.m. UTC | #2
2014-06-29 20:47 GMT+02:00 Tim Shen <timshen91@gmail.com>:
> On Sun, Jun 29, 2014 at 10:18 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
>> Alternatively, we could just make them local statics instead of member
>> data and still remove the duplciation (see attached).
>
> This is a good idea. Can we use constexpr for the functions/static variables?

Not so for local statics within constexpr functions, but you could
have constexpr static data members, yes.

- Daniel
diff mbox

Patch

commit 82f3e9fa7d16a677bb9ebc6bc3da12c1209c2df5
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sun Jun 29 17:58:59 2014 +0100

    	* include/bits/regex_scanner.h (_ScannerBase): Replace member data
    	with static member functions.
    	* include/bits/regex_scanner.tcc (_ScannerBase): Likewise.

diff --git a/libstdc++-v3/include/bits/regex_scanner.h b/libstdc++-v3/include/bits/regex_scanner.h
index 6627db9..fdc1210 100644
--- a/libstdc++-v3/include/bits/regex_scanner.h
+++ b/libstdc++-v3/include/bits/regex_scanner.h
@@ -1,4 +1,4 @@ 
-// class template regex -*- C++ -*-
+// Regex implementation -*- C++ -*-
 
 // Copyright (C) 2013-2014 Free Software Foundation, Inc.
 //
@@ -92,13 +92,13 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : _M_state(_S_state_normal),
     _M_flags(__flags),
     _M_escape_tbl(_M_is_ecma()
-		  ? _M_ecma_escape_tbl
-		  : _M_awk_escape_tbl),
+		  ? _S_ecma_escape_tbl()
+		  : _S_awk_escape_tbl()),
     _M_spec_char(_M_is_ecma()
-		 ? _M_ecma_spec_char
+		 ? _S_ecma_spec_char()
 		 : _M_is_basic()
-		 ? _M_basic_spec_char
-		 : _M_extended_spec_char),
+		 ? _S_basic_spec_char()
+		 : _S_extended_spec_char()),
     _M_at_bracket_start(false)
     { }
 
@@ -138,46 +138,60 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { return _M_flags & regex_constants::awk; }
 
   protected:
-    const std::pair<char, _TokenT> _M_token_tbl[9] =
-      {
-	{'^', _S_token_line_begin},
-	{'$', _S_token_line_end},
-	{'.', _S_token_anychar},
-	{'*', _S_token_closure0},
-	{'+', _S_token_closure1},
-	{'?', _S_token_opt},
-	{'|', _S_token_or},
-	{'\n', _S_token_or}, // grep and egrep
-	{'\0', _S_token_or},
-      };
-    const std::pair<char, char> _M_ecma_escape_tbl[8] =
-      {
-	{'0', '\0'},
-	{'b', '\b'},
-	{'f', '\f'},
-	{'n', '\n'},
-	{'r', '\r'},
-	{'t', '\t'},
-	{'v', '\v'},
-	{'\0', '\0'},
-      };
-    const std::pair<char, char> _M_awk_escape_tbl[11] =
-      {
-	{'"', '"'},
-	{'/', '/'},
-	{'\\', '\\'},
-	{'a', '\a'},
-	{'b', '\b'},
-	{'f', '\f'},
-	{'n', '\n'},
-	{'r', '\r'},
-	{'t', '\t'},
-	{'v', '\v'},
-	{'\0', '\0'},
-      };
-    const char* _M_ecma_spec_char = "^$\\.*+?()[]{}|";
-    const char* _M_basic_spec_char = ".[\\*^$";
-    const char* _M_extended_spec_char = ".[\\()*+?{|^$";
+    static const std::pair<char, _TokenT>* _S_token_tbl()
+    {
+      static const std::pair<char, _TokenT> __token_tbl[9] =
+	{
+	  {'^', _S_token_line_begin},
+	  {'$', _S_token_line_end},
+	  {'.', _S_token_anychar},
+	  {'*', _S_token_closure0},
+	  {'+', _S_token_closure1},
+	  {'?', _S_token_opt},
+	  {'|', _S_token_or},
+	  {'\n', _S_token_or}, // grep and egrep
+	  {'\0', _S_token_or},
+	};
+      return __token_tbl;
+    }
+
+    static const std::pair<char, char>* _S_ecma_escape_tbl()
+    {
+      static const std::pair<char, char> __ecma_escape_tbl[8] =
+	{
+	  {'0', '\0'},
+	  {'b', '\b'},
+	  {'f', '\f'},
+	  {'n', '\n'},
+	  {'r', '\r'},
+	  {'t', '\t'},
+	  {'v', '\v'},
+	  {'\0', '\0'},
+	};
+      return __ecma_escape_tbl;
+    }
+    static const std::pair<char, char>* _S_awk_escape_tbl()
+    {
+      static const std::pair<char, char> __awk_escape_tbl[11] =
+	{
+	  {'"', '"'},
+	  {'/', '/'},
+	  {'\\', '\\'},
+	  {'a', '\a'},
+	  {'b', '\b'},
+	  {'f', '\f'},
+	  {'n', '\n'},
+	  {'r', '\r'},
+	  {'t', '\t'},
+	  {'v', '\v'},
+	  {'\0', '\0'},
+	};
+      return __awk_escape_tbl;
+    }
+
+    static const char* _S_ecma_spec_char() { return "^$\\.*+?()[]{}|"; }
+    static const char* _S_basic_spec_char() { return ".[\\*^$"; }
+    static const char* _S_extended_spec_char() { return ".[\\()*+?{|^$"; }
 
     _StateT                       _M_state;
     _FlagT                        _M_flags;
diff --git a/libstdc++-v3/include/bits/regex_scanner.tcc b/libstdc++-v3/include/bits/regex_scanner.tcc
index 818e47b..ed88f71 100644
--- a/libstdc++-v3/include/bits/regex_scanner.tcc
+++ b/libstdc++-v3/include/bits/regex_scanner.tcc
@@ -170,7 +170,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		&& __c != '}')
 	       || (_M_is_grep() && __c == '\n'))
 	{
-	  auto __it = _M_token_tbl;
+	  auto __it = _S_token_tbl();
 	  auto __narrowc = _M_ctype.narrow(__c, '\0');
 	  for (; __it->first != '\0'; ++__it)
 	    if (__it->first == __narrowc)