summaryrefslogtreecommitdiff
path: root/libstdc++-v3/libsupc++
diff options
context:
space:
mode:
authorglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-17 17:47:36 +0000
committerglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-17 17:47:36 +0000
commite347a302c7eb69690b679a2f367fb37df797448f (patch)
tree9d513fa25588d3793a824ee7c970c7b6469ff54d /libstdc++-v3/libsupc++
parent0f718e59b1cffee9e7ac04fdd0be3725f072c61c (diff)
downloadgcc-e347a302c7eb69690b679a2f367fb37df797448f.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210560 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/libsupc++')
-rw-r--r--libstdc++-v3/libsupc++/new_op.cc5
-rw-r--r--libstdc++-v3/libsupc++/new_opnt.cc6
2 files changed, 4 insertions, 7 deletions
diff --git a/libstdc++-v3/libsupc++/new_op.cc b/libstdc++-v3/libsupc++/new_op.cc
index 4a3e85848ce..fb54488e608 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 b83da60b542..968082f4096 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;