This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]