This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: Add branch prediction
authorKarl Williamson <khw@cpan.org>
Mon, 13 Feb 2017 19:02:54 +0000 (12:02 -0700)
committerKarl Williamson <khw@cpan.org>
Tue, 14 Feb 2017 04:24:08 +0000 (21:24 -0700)
The input is far more likely to be well-formed than not.

toke.c

diff --git a/toke.c b/toke.c
index 864fda7..b7d78f7 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -747,9 +747,10 @@ Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)
 
        s = SvPV_const(line, len);
 
-        if (SvUTF8(line) && ! is_utf8_string_loc((U8 *) s,
-                                                 SvCUR(line),
-                                                 &first_bad_char_loc))
+        if (   SvUTF8(line)
+            && UNLIKELY(! is_utf8_string_loc((U8 *) s,
+                                             SvCUR(line),
+                                             &first_bad_char_loc)))
         {
             _force_out_malformed_utf8_message(first_bad_char_loc,
                                               (U8 *) s + SvCUR(line),
@@ -2724,7 +2725,9 @@ S_get_and_check_backslash_N_name(pTHX_ const char* s, const char* const e)
         const U8* first_bad_char_loc;
         STRLEN len;
         const char* const str = SvPV_const(res, len);
-        if (! is_utf8_string_loc((U8 *) str, len, &first_bad_char_loc)) {
+        if (UNLIKELY(! is_utf8_string_loc((U8 *) str, len,
+                                          &first_bad_char_loc)))
+        {
             _force_out_malformed_utf8_message(first_bad_char_loc,
                                               (U8 *) PL_parser->bufend,
                                               0,