toke.c: Extract into a named string constant
authorKarl Williamson <khw@cpan.org>
Sat, 4 Oct 2014 17:13:45 +0000 (11:13 -0600)
committerKarl Williamson <khw@cpan.org>
Tue, 7 Oct 2014 14:51:10 +0000 (08:51 -0600)
This moves a literal double-quoted string into a const variable, so that
it only need be written out once, and its  size can be compiler-computed
and used as another const variable.  Hence, mnemonics are used instead
of bare numbers.

toke.c

diff --git a/toke.c b/toke.c
index 462d5f0..09ef5b2 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3363,13 +3363,18 @@ S_scan_const(pTHX_ char *start)
                                  * through the string.  Each character takes up
                                  * 2 hex digits plus either a trailing dot or
                                  * the "}" */
+                                const char initial_text[] = "\\N{U+";
+                                const STRLEN initial_len = sizeof(initial_text)
+                                                           - 1;
                                 d = off + SvGROW(sv, off
                                                     + 3 * len
-                                                    + 6 /* For the "\N{U+", and
-                                                           trailing NUL */
+
+                                                    /* +1 for trailing NUL */
+                                                    + initial_len + 1
+
                                                     + (STRLEN)(send - e));
-                                Copy("\\N{U+", d, 5, char);
-                                d += 5;
+                                Copy(initial_text, d, initial_len, char);
+                                d += initial_len;
                                 while (str < str_end) {
                                     char hex_string[4];
                                     int len =