diff options
-rw-r--r-- | libstdc++-v3/ChangeLog | 5 | ||||
-rw-r--r-- | libstdc++-v3/libsupc++/new_op.cc | 5 | ||||
-rw-r--r-- | libstdc++-v3/libsupc++/new_opnt.cc | 6 |
3 files changed, 9 insertions, 7 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8c6b15b..429b168 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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 diff --git a/libstdc++-v3/libsupc++/new_op.cc b/libstdc++-v3/libsupc++/new_op.cc index 4a3e858..fb54488 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 b83da60..968082f 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; |