summaryrefslogtreecommitdiffstats
path: root/include/stdlib.h
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2009-01-31 18:27:02 +0000
committerdas <das@FreeBSD.org>2009-01-31 18:27:02 +0000
commit61dc3e056cc2ad51f33f296f1cfda0ece440b85e (patch)
tree86563ca98ba62d850839a916a23d185416bda1b7 /include/stdlib.h
parentfb1404080f89a63cdf36da668e5ff4fc65cfa4d9 (diff)
downloadFreeBSD-src-61dc3e056cc2ad51f33f296f1cfda0ece440b85e.zip
FreeBSD-src-61dc3e056cc2ad51f33f296f1cfda0ece440b85e.tar.gz
Add a function attribute called `__malloc_like', which informs gcc
that the annotated function returns a pointer that doesn't alias any extant pointer. This results in a 50%+ speedup in microbenchmarks such as the following: char *cp = malloc(1), *buf = malloc(BUF); for (i = 0; i < BUF; i++) buf[i] = *cp; In real programs, your mileage will vary. Note that gcc already performs this optimization automatically for any function called `malloc', `calloc', `strdup', or `strndup' unless -fno-builtins is used.
Diffstat (limited to 'include/stdlib.h')
-rw-r--r--include/stdlib.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/stdlib.h b/include/stdlib.h
index 0a83270..91be536 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -88,14 +88,14 @@ int atoi(const char *);
long atol(const char *);
void *bsearch(const void *, const void *, size_t,
size_t, int (*)(const void *, const void *));
-void *calloc(size_t, size_t);
+void *calloc(size_t, size_t) __malloc_like;
div_t div(int, int) __pure2;
void exit(int) __dead2;
void free(void *);
char *getenv(const char *);
long labs(long) __pure2;
ldiv_t ldiv(long, long) __pure2;
-void *malloc(size_t);
+void *malloc(size_t) __malloc_like;
int mblen(const char *, size_t);
size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
int mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
OpenPOWER on IntegriCloud