From 35e5392d78ed72ffdbe2cd90bc35faf679493bea Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Mon, 6 Jan 2020 18:49:41 -0700 Subject: grok_bin_oct_hex(): Add branch prediction --- numeric.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index d9e7b3581c..fe5e0f723b 100644 --- a/numeric.c +++ b/numeric.c @@ -335,10 +335,12 @@ Perl_grok_bin_oct_hex(pTHX_ const char *start, if (_generic_isCC(*s, class_bit)) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. - With gcc seems to be much straighter code than old scan_hex. */ + With gcc seems to be much straighter code than old scan_hex. + (khw suspects that adding a LIKELY() just above would do the + same thing) */ redo: if (!overflowed) { - if (value <= max_div) { + if (LIKELY(value <= max_div)) { value = (value << shift) | XDIGIT_VALUE(*s); /* Note XDIGIT_VALUE() is branchless, works on binary * and octal as well, so can be used here, without -- cgit v1.2.1