]> gcc.gnu.org Git - gcc.git/commitdiff
* runtime/memory.c (xmallocarray): Avoid division for the common case.
authorJakub Jelinek <jakub@redhat.com>
Mon, 4 Aug 2014 15:46:33 +0000 (17:46 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 4 Aug 2014 15:46:33 +0000 (17:46 +0200)
From-SVN: r213593

libgfortran/ChangeLog
libgfortran/runtime/memory.c

index 80f87523a69503be5476a74532756c12819bae7b..77afd166d075aadd615032e6515e47238312990b 100644 (file)
@@ -1,3 +1,7 @@
+2014-08-04  Jakub Jelinek  <jakub@redhat.com>
+
+       * runtime/memory.c (xmallocarray): Avoid division for the common case.
+
 2014-07-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/61632
index 501d870b83caebf8d43eb8894d27147eb87cce61..16f06065e2b5f397f1f30ce3b8492dbb528721a3 100644 (file)
@@ -56,7 +56,9 @@ xmallocarray (size_t nmemb, size_t size)
 
   if (!nmemb || !size)
     size = nmemb = 1;
-  else if (nmemb > SIZE_MAX / size)
+#define HALF_SIZE_T (((size_t) 1) << (__CHAR_BIT__ * sizeof (size_t) / 2))
+  else if (__builtin_expect ((nmemb | size) >= HALF_SIZE_T, 0)
+          && nmemb > SIZE_MAX / size)
     {
       errno = ENOMEM;
       os_error ("Integer overflow in xmallocarray");
This page took 0.064408 seconds and 5 git commands to generate.