summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
authorDavid Schultz <das@FreeBSD.org>2009-01-31 18:27:02 +0000
committerDavid Schultz <das@FreeBSD.org>2009-01-31 18:27:02 +0000
commit544048ecef8fd8480d850fe80ba04ab9d7f8bdef (patch)
tree86563ca98ba62d850839a916a23d185416bda1b7 /include/string.h
parent13fd4d21637e98c03983ed6c5972695dfa232fe9 (diff)
downloadsrc-test2-544048ecef8fd8480d850fe80ba04ab9d7f8bdef.tar.gz
src-test2-544048ecef8fd8480d850fe80ba04ab9d7f8bdef.zip
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.
Notes
Notes: svn path=/head/; revision=187961
Diffstat (limited to 'include/string.h')
-rw-r--r--include/string.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/string.h b/include/string.h
index 32a9ad3e5608..4770d101a139 100644
--- a/include/string.h
+++ b/include/string.h
@@ -78,7 +78,7 @@ int strcoll(const char *, const char *);
char *strcpy(char * __restrict, const char * __restrict);
size_t strcspn(const char *, const char *) __pure;
#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
-char *strdup(const char *);
+char *strdup(const char *) __malloc_like;
#endif
char *strerror(int);
#if __POSIX_VISIBLE >= 200112
@@ -96,7 +96,7 @@ char *strncat(char * __restrict, const char * __restrict, size_t);
int strncmp(const char *, const char *, size_t) __pure;
char *strncpy(char * __restrict, const char * __restrict, size_t);
#if __BSD_VISIBLE
-char *strndup(const char *, size_t);
+char *strndup(const char *, size_t) __malloc_like;
char *strnstr(const char *, const char *, size_t) __pure;
#endif
char *strpbrk(const char *, const char *) __pure;