diff options
author | Jakub Jelinek <jakub@redhat.com> | 2014-08-04 17:46:33 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2014-08-04 17:46:33 +0200 |
commit | 62c986afde031d141961d2619a860def836c8e9b (patch) | |
tree | 5286463521855c483f9a00398080e73af7eda4fc /libgfortran/runtime | |
parent | 3696163cb43bdd7c3a22bef46a0e3f4576d0fc44 (diff) | |
download | gcc-62c986afde031d141961d2619a860def836c8e9b.zip gcc-62c986afde031d141961d2619a860def836c8e9b.tar.gz gcc-62c986afde031d141961d2619a860def836c8e9b.tar.bz2 |
* runtime/memory.c (xmallocarray): Avoid division for the common case.
From-SVN: r213593
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r-- | libgfortran/runtime/memory.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c index 501d870..16f0606 100644 --- a/libgfortran/runtime/memory.c +++ b/libgfortran/runtime/memory.c @@ -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"); |