From: Marc Glisse Date: Sat, 17 May 2014 17:47:36 +0000 (+0200) Subject: new_op.cc: Factor the calls to malloc, use __builtin_expect. X-Git-Tag: releases/gcc-5.1.0~7501 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80333d3d23015d7e6e3a4380ccea5a04d807b9db;p=thirdparty%2Fgcc.git new_op.cc: Factor the calls to malloc, use __builtin_expect. 2014-05-17 Marc Glisse * libsupc++/new_op.cc: Factor the calls to malloc, use __builtin_expect. * libsupc++/new_opnt.cc: Likewise. From-SVN: r210560 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8c6b15b346f1..429b1683096d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2014-05-17 Marc Glisse + + * libsupc++/new_op.cc: Factor the calls to malloc, use __builtin_expect. + * libsupc++/new_opnt.cc: Likewise. + 2014-05-17 Jonathan Wakely PR libstdc++/60966 diff --git a/libstdc++-v3/libsupc++/new_op.cc b/libstdc++-v3/libsupc++/new_op.cc index 4a3e85848ce5..fb54488e6080 100644 --- a/libstdc++-v3/libsupc++/new_op.cc +++ b/libstdc++-v3/libsupc++/new_op.cc @@ -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; diff --git a/libstdc++-v3/libsupc++/new_opnt.cc b/libstdc++-v3/libsupc++/new_opnt.cc index b83da60b542d..968082f4096e 100644 --- a/libstdc++-v3/libsupc++/new_opnt.cc +++ b/libstdc++-v3/libsupc++/new_opnt.cc @@ -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;