This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Some nano-optimizations
authorKarl Williamson <khw@cpan.org>
Sat, 9 Apr 2016 21:16:59 +0000 (15:16 -0600)
committerKarl Williamson <khw@cpan.org>
Mon, 9 May 2016 17:24:38 +0000 (11:24 -0600)
Reorder two branches so the most likely is tested before the much less
likely, and add some UNLIKELY()

locale.c

index b304a28..0116be4 100644 (file)
--- 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;
        }