]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
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 8c6b15b346f1543287cdb19bd4bd5e4d7996eb7c..429b1683096d63ae0a14030f39f347c9263a3dd7 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 4a3e85848ce5ec769597f93a98720fe86ec8b505..fb54488e60809d879b818a7b2edd7831bbba4190 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 b83da60b542d09ab57b272ef770f23bff0c9bc87..968082f4096eaf44ef7619dbfc2af6e2f5f9b9dc 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;