new_op.cc: Factor the calls to malloc, use __builtin_expect.
authorMarc Glisse <marc.glisse@inria.fr>
Sat, 17 May 2014 17:47:36 +0000 (19:47 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Sat, 17 May 2014 17:47:36 +0000 (17:47 +0000)
2014-05-17  Marc Glisse  <marc.glisse@inria.fr>

* libsupc++/new_op.cc: Factor the calls to malloc, use __builtin_expect.
* libsupc++/new_opnt.cc: Likewise.

From-SVN: r210560

libstdc++-v3/ChangeLog
libstdc++-v3/libsupc++/new_op.cc
libstdc++-v3/libsupc++/new_opnt.cc

index 8c6b15b..429b168 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-17  Marc Glisse  <marc.glisse@inria.fr>
+
+       * libsupc++/new_op.cc: Factor the calls to malloc, use __builtin_expect.
+       * libsupc++/new_opnt.cc: Likewise.
+
 2014-05-17  Jonathan Wakely  <jwakely@redhat.com>
 
        PR libstdc++/60966
index 4a3e858..fb54488 100644 (file)
@@ -46,14 +46,13 @@ operator new (std::size_t sz) _GLIBCXX_THROW (std::bad_alloc)
   /* malloc (0) is unpredictable; avoid it.  */
   if (sz == 0)
     sz = 1;
-  p = (void *) malloc (sz);
-  while (p == 0)
+
+  while (__builtin_expect ((p = malloc (sz)) == 0, false))
     {
       new_handler handler = std::get_new_handler ();
       if (! handler)
        _GLIBCXX_THROW_OR_ABORT(bad_alloc());
       handler ();
-      p = (void *) malloc (sz);
     }
 
   return p;
index b83da60..968082f 100644 (file)
@@ -39,8 +39,8 @@ operator new (std::size_t sz, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
   /* malloc (0) is unpredictable; avoid it.  */
   if (sz == 0)
     sz = 1;
-  p = (void *) malloc (sz);
-  while (p == 0)
+
+  while (__builtin_expect ((p = malloc (sz)) == 0, false))
     {
       new_handler handler = std::get_new_handler ();
       if (! handler)
@@ -53,8 +53,6 @@ operator new (std::size_t sz, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
        {
          return 0;
        }
-
-      p = (void *) malloc (sz);
     }
 
   return p;