From: Karl Williamson Date: Sat, 9 Apr 2016 21:16:59 +0000 (-0600) Subject: locale.c: Some nano-optimizations X-Git-Tag: v5.25.1~117 X-Git-Url: https://perl5.git.perl.org/perl5.git/commitdiff_plain/bb0f664e88915ea62cf282157a8672ea660cf450?ds=sidebyside locale.c: Some nano-optimizations Reorder two branches so the most likely is tested before the much less likely, and add some UNLIKELY() --- diff --git a/locale.c b/locale.c index b304a28..0116be4 100644 --- a/locale.c +++ b/locale.c @@ -1242,7 +1242,7 @@ Perl_mem_collxfrm(pTHX_ const char *s, STRLEN len, STRLEN *xlen) xAlloc = sizeof(PL_collation_ix) + PL_collxfrm_base + (PL_collxfrm_mult * len) + 1; Newx(xbuf, xAlloc, char); - if (! xbuf) + if (UNLIKELY(! xbuf)) goto bad; *(U32*)xbuf = PL_collation_ix; @@ -1252,13 +1252,14 @@ Perl_mem_collxfrm(pTHX_ const char *s, STRLEN len, STRLEN *xlen) for (;;) { xused = strxfrm(xbuf + xout, s + xin, xAlloc - xout); - if (xused >= PERL_INT_MAX) - goto bad; if ((STRLEN)xused < xAlloc - xout) break; + + if (UNLIKELY(xused >= PERL_INT_MAX)) + goto bad; xAlloc = (2 * xAlloc) + 1; Renew(xbuf, xAlloc, char); - if (! xbuf) + if (UNLIKELY(! xbuf)) goto bad; }