]> git.eshelyaron.com Git - emacs.git/commit
Refactor regex character class parsing in [:name:]
authorMichal Nazarewicz <mina86@mina86.com>
Sun, 17 Jul 2016 01:09:38 +0000 (03:09 +0200)
committerMichal Nazarewicz <mina86@mina86.com>
Tue, 2 Aug 2016 13:39:10 +0000 (15:39 +0200)
commit4538a5e37e8dacde4b3e828d832c4c558a146912
tree43a158bf0635a01bf5946730ac439fd0b3b8f606
parente7257061317c604492d20f26f312b9e925aa1860
Refactor regex character class parsing in [:name:]

re_wctype function is used in three separate places and in all of
those places almost exact code extracting the name from [:name:]
surrounds it.  Furthermore, re_wctype requires a NUL-terminated
string, so the name of the character class is copied to a temporary
buffer.

The code duplication and unnecessary memory copying can be avoided by
pushing the responsibility of parsing the whole [:name:] sequence to
the function.

Furthermore, since now the function has access to the length of the
character class name (since it’s doing the parsing), it can take
advantage of that information in skipping some string comparisons and
using a constant-length memcmp instead of strcmp which needs to take
care of NUL bytes.

* src/regex.c (re_wctype): Delete function.  Replace it with:
(re_wctype_parse): New function which parses a whole [:name:] string
and returns a RECC_* constant or -1 if the string is not of [:name:]
format.
(regex_compile): Use re_wctype_parse.
* src/syntax.c (skip_chars): Use re_wctype_parse.
src/regex.c
src/regex.h
src/syntax.c