This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] xmalloc.c: add unlikely ()
- From: Marek Polacek <mpolacek at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Sat, 14 May 2011 04:49:34 +0200
- Subject: [PATCH] xmalloc.c: add unlikely ()
Even though this should be handled by the gcc's tree_estimate_probability,
adding the unlikely () to conditions which are almost never true shouldn't
hurt either. Yes, it compiles. OK to apply?
2011-05-14 Marek Polacek <mpolacek@redhat.com>
* xmalloc.c (xmalloc, xcalloc, xrealloc): Add unlikely ().
--- elfutils/lib/xmalloc.c.mp 2011-05-14 04:35:36.343212076 +0200
+++ elfutils/lib/xmalloc.c 2011-05-14 04:38:35.313787891 +0200
@@ -1,5 +1,5 @@
/* Convenience functions for allocation.
- Copyright (C) 2006 Red Hat, Inc.
+ Copyright (C) 2006, 2011 Red Hat, Inc.
This file is part of Red Hat elfutils.
Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -47,7 +47,7 @@ xmalloc (n)
void *p;
p = malloc (n);
- if (p == NULL)
+ if (unlikely (p == NULL))
error (EXIT_FAILURE, 0, _("memory exhausted"));
return p;
}
@@ -61,7 +61,7 @@ xcalloc (n, s)
void *p;
p = calloc (n, s);
- if (p == NULL)
+ if (unlikely (p == NULL))
error (EXIT_FAILURE, 0, _("memory exhausted"));
return p;
}
@@ -75,7 +75,7 @@ xrealloc (p, n)
size_t n;
{
p = realloc (p, n);
- if (p == NULL)
+ if (unlikely (p == NULL))
error (EXIT_FAILURE, 0, _("memory exhausted"));
return p;
}