Skip to contentSkip to conversation

perf: add GCC optimization to memory allocating functions

PATCH In review Davidlohr Bueso 2 participants 3 messages Nov 26, 2010 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: add GCC optimization to memory allocating functions

From: Davidlohr Bueso <[email protected]>

We can benefit from the alloc_size attribute in xrealloc and zalloc.

---
 tools/perf/util/util.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/util.h +3 -2
index 7562707..41a5067 100644
@@ -182,10 +182,11 @@ static inline char *gitstrchrnul(const char *s, int c)
  * Wrappers:
  */
 extern char *xstrdup(const char *str);
-extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
+extern void *xrealloc(void *ptr, size_t size) __attribute__((weak, alloc_size(2)));
 
 
-static inline void *zalloc(size_t size)
+static inline __attribute__((alloc_size(1)))
+void *zalloc(size_t size)
 {
 	return calloc(1, size);
 }
Signature · 1 line
1.7.1
#1 lore raw
Quoted 3 lines · Davidlohr Bueso

From: Davidlohr Bueso <[email protected]>

We can benefit from the alloc_size attribute in xrealloc and zalloc.

What's this alloc_size attribute do?

#2 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Davidlohr Bueso

From: Davidlohr Bueso <[email protected]>

We can benefit from the alloc_size attribute in xrealloc and zalloc.

What's this alloc_size attribute do?

Quoting from http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html:

"The alloc_size attribute is used to tell the compiler that the function return value points to memory, where the size is given by one or two of the functions parameters. GCC uses this information to improve the correctness of __builtin_object_size."