[patch 1/N] std::regex refactoring - _BracketMatcher
Jonathan Wakely
jwakely@redhat.com
Mon Apr 28 13:04:00 GMT 2014
Hi,
I've been looking through the regex code and have a few ideas for
simplifications or optimisations that I'd like to share.
This first patch is for _BracketMatcher. We only use std::bitset when
is_same<_CharT, char> so 8 * sizeof(_CharT) should be __CHAR_BIT__
instead. We also only user _UnsignedCharT when is_same<_CharT, char>
so that can just be simplified to unsigned char.
The contents of _BracketMatcher::_M_char_set are not sorted and can
contain duplicates in the current code. Making that a sorted, unique
list in _BracketMatcher::_M_ready() allows a binary search instead of
linear search. This improves worst case performance for pathological
regular expressions like std::wregex('['+std::wstring(1000, 'a')+"b]")
but I'm not sure if it helps in the common case.
Finally, in the non-char case the _CacheT member is an unused empty
object, so having that as the first member requires 7 bytes of
padding. Re-ordering the members reduces the size of a non-char
_BracketMatcher by 8 bytes (but it's still a whopping 96 bytes).
(For a char _BracketMatcher the bitset cache makes it 128 bytes,
this patch doesn't change that).
Thoughts?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: re1.patch
Type: text/x-diff
Size: 3178 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20140428/6e0268be/attachment.bin>
More information about the Libstdc++
mailing list