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  <[email protected]>

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

_______________________________________________
elfutils-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/elfutils-devel

Reply via email to