Regex refactoring

Jonathan Wakely jwakely.gcc@gmail.com
Fri Nov 8 19:10:00 GMT 2013


I'm also thinking about this change to avoid allocating memory in
regex::assign().  It isn't exactly what the standard requires, but I'm
not sure if the difference matters:

--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -618,7 +618,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
        */
       basic_regex&
       assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
-      { return this->assign(string_type(__p, __len), __flags); }
+      { return this->assign(__p, __p + __len, __flags); }

       /**
        * @brief Assigns a new regular expression to a regex object from a
@@ -635,12 +635,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
        basic_regex&
        assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s,
               flag_type __flags = ECMAScript)
-       {
-         _M_flags = __flags;
-         _M_automaton = __detail::__compile_nfa(__s.begin(), __s.end(),
-                                                _M_traits, _M_flags);
-         return *this;
-       }
+       { return this->assign(__s.begin(), __s.end(), __flags); }

       /**
        * @brief Assigns a new regular expression to a regex object.
@@ -659,7 +654,12 @@ _GLIBCXX_END_NAMESPACE_VERSION
        basic_regex&
        assign(_InputIterator __first, _InputIterator __last,
               flag_type __flags = ECMAScript)
-       { return this->assign(string_type(__first, __last), __flags); }
+       {
+         _M_flags = __flags;
+         _M_automaton = __detail::__compile_nfa(__first, __last,
+                                                _M_traits, _M_flags);
+         return *this;
+       }

       /**
        * @brief Assigns a new regular expression to a regex object.



More information about the Libstdc++ mailing list