all files: use restrict key word for all pointer arguments

Limit the effects of pointer aliasing and aiding caching
optimizations.

http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-10-23 22:18:38 +02:00
parent 235825b084
commit 6b47d9ffaf
6 changed files with 33 additions and 32 deletions

View file

@ -14,7 +14,8 @@ AC_GNU_SOURCE
# Checks for programs
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CC_C99
AC_C_RESTRICT
AC_PROG_CXX
AC_PROG_MAKE_SET
AC_PROG_LIBTOOL

View file

@ -145,9 +145,9 @@ struct macaddr_t *macaddr;
/* Function prototypes */
int prepare_memory(void);
int parse_leases(void);
void parse_config(int, char *, struct shared_network_t *)
void parse_config(int, const char *__restrict, struct shared_network_t *__restrict)
__attribute__ ((nonnull(2, 3)));
int nth_field(int n, char *dest, const char *src)
int nth_field(int n, char *__restrict dest, const char *__restrict src)
__attribute__ ((nonnull(2, 3)))
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
__attribute__ ((__hot__))
@ -155,7 +155,7 @@ int nth_field(int n, char *dest, const char *src)
;
int prepare_data(void);
int do_counting(void);
void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
void flip_ranges(struct range_t *__restrict ranges, struct range_t *__restrict tmp_ranges)
__attribute__ ((nonnull(1, 2)));
/* support functions */
void *safe_malloc(const size_t size)
@ -166,15 +166,15 @@ void *safe_malloc(const size_t size)
#endif
#endif
;
void *safe_realloc(void *ptr, const size_t size);
char *safe_strdup(const char *str) __attribute__ ((nonnull(1)));
int xstrstr(char *a, char *b, int len);
void *safe_realloc(void *__restrict ptr, const size_t size);
char *safe_strdup(const char *__restrict str) __attribute__ ((nonnull(1)));
int xstrstr(char *__restrict a, char *__restrict b, int len);
void print_version(void) __attribute__ ((noreturn));
void usage(int status) __attribute__ ((noreturn));
/* qsort required functions... */
/* ...for ranges and... */
int intcomp(const void *x, const void *y) __attribute__ ((nonnull(1, 2)));
int rangecomp(const void *r1, const void *r2)
int intcomp(const void *__restrict x, const void *__restrict y) __attribute__ ((nonnull(1, 2)));
int rangecomp(const void *__restrict r1, const void *__restrict r2)
__attribute__ ((nonnull(1, 2)));
/* sort function pointer and functions */
int sort_name(void);
@ -187,9 +187,9 @@ unsigned long int ret_touched(struct range_t r);
unsigned long int ret_tc(struct range_t r);
unsigned long int ret_tcperc(struct range_t r);
void field_selector(char c);
int get_order(struct range_t *left, struct range_t *right)
int get_order(struct range_t *__restrict left, struct range_t *__restrict right)
__attribute__ ((nonnull(1, 2)));
void mergesort_ranges(struct range_t *orig, int size, struct range_t *temp)
void mergesort_ranges(struct range_t *__restrict orig, int size, struct range_t *__restrict temp)
__attribute__ ((nonnull(1, 3)));
/* output function pointer and functions */
int (*output_analysis) (void);

View file

@ -198,7 +198,7 @@ int parse_leases(void)
* first field is 1 and not 0 like C programs should have. Question of
* semantics, send mail to author if this annoys. All performance boosts for
* this function are well come. */
int nth_field(int n, char *dest, const char *src)
int nth_field(int n, char *restrict dest, const char *restrict src)
{
int i, j = 0, wordn = 0, len;
@ -225,7 +225,7 @@ int nth_field(int n, char *dest, const char *src)
}
/* dhcpd.conf interesting words */
int is_interesting_config_clause(char *s)
int is_interesting_config_clause(char *restrict s)
{
if (strstr(s, "range")) {
return 3;
@ -239,8 +239,8 @@ int is_interesting_config_clause(char *s)
}
/* FIXME: This spagetti monster function need to be rewrote at least ones. */
void parse_config(int is_include, char *config_file,
struct shared_network_t *shared_p)
void parse_config(int is_include, const char *restrict config_file,
struct shared_network_t *restrict shared_p)
{
FILE *dhcpd_config;
int newclause = true, argument = false, comment =

View file

@ -82,7 +82,7 @@ int
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
__attribute__ ((hot))
#endif
xstrstr(char *a, char *b, int len)
xstrstr(char *restrict a, char *restrict b, int len)
{
int i;
/* two spaces are very common in lease file, after them
@ -105,7 +105,7 @@ int
}
/* Simple strdup wrapper */
char *safe_strdup(const char *str)
char *safe_strdup(const char *restrict str)
{
char *ret = strdup(str);
@ -114,7 +114,7 @@ char *safe_strdup(const char *str)
return ret;
}
void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
void flip_ranges(struct range_t *restrict ranges, struct range_t *restrict tmp_ranges)
{
unsigned int i = num_ranges - 1, j;

View file

@ -313,7 +313,7 @@ int output_xml(void)
return 0;
}
void html_header(FILE * f)
void html_header(FILE *restrict f)
{
char outstr[200];
struct tm *tmp;
@ -387,7 +387,7 @@ void html_header(FILE * f)
fprintf(f, "<a name=\"ranges\">The lease file mtime: %s</a>", outstr);
}
void html_footer(FILE * f)
void html_footer(FILE *restrict f)
{
fprintf(f, "<p><br></p>\n");
fprintf(f, "<hr>\n");
@ -403,44 +403,44 @@ void html_footer(FILE * f)
fprintf(f, "</html>\n");
}
void newrow(FILE * f)
void newrow(FILE *restrict f)
{
fprintf(f, "<tr>\n");
}
void endrow(FILE * f)
void endrow(FILE *restrict f)
{
fprintf(f, "</tr>\n\n");
}
void output_line(FILE * f, char *type, char *class, char *text)
void output_line(FILE *restrict f, char *restrict type, char *restrict class, char *restrict text)
{
fprintf(f, " <%s class=%s>%s</%s>\n", type, class, text, type);
}
void output_long(FILE * f, char *type, unsigned long unlong)
void output_long(FILE *restrict f, char *restrict type, unsigned long unlong)
{
fprintf(f, " <%s class=ralign>%lu</%s>\n", type, unlong, type);
}
void output_float(FILE * f, char *type, float fl)
void output_float(FILE * f, char *restrict type, float fl)
{
fprintf(f, " <%s class=ralign>%.3f</%s>\n", type, fl, type);
}
void table_start(FILE * f)
void table_start(FILE *restrict f)
{
fprintf(f, "<table width=\"75%%\" ");
fprintf(f, "class=\"%s\" ", PACKAGE_NAME);
fprintf(f, "summary=\"ISC dhcpd pool usage report\">\n");
}
void table_end(FILE * f)
void table_end(FILE *restrict f)
{
fprintf(f, "</table>\n");
}
void newsection(FILE * f, char *title)
void newsection(FILE *restrict f, char *restrict title)
{
newrow(f);
output_line(f, "td", "calign", "&nbsp;");

View file

@ -44,7 +44,7 @@
#include "dhcpd-pools.h"
/* Sort functions for range sorting */
int intcomp(const void *x, const void *y)
int intcomp(const void *restrict x, const void *restrict y)
{
if (*(uint32_t *) x < *(uint32_t *) y)
return -1;
@ -54,7 +54,7 @@ int intcomp(const void *x, const void *y)
return 0;
}
int rangecomp(const void *r1, const void *r2)
int rangecomp(const void *restrict r1, const void *restrict r2)
{
if ((((struct range_t *)r1)->first_ip) <
(((struct range_t *)r2)->first_ip))
@ -139,7 +139,7 @@ void field_selector(char c)
}
/* Needed to support multiple key sorting. */
int get_order(struct range_t *left, struct range_t *right)
int get_order(struct range_t *restrict left, struct range_t *restrict right)
{
int i, len, ret;
unsigned long int lint, rint;
@ -178,7 +178,7 @@ int get_order(struct range_t *left, struct range_t *right)
return (0);
}
void mergesort_ranges(struct range_t *orig, int size, struct range_t *temp)
void mergesort_ranges(struct range_t *restrict orig, int size, struct range_t *restrict temp)
{
int left, right, i;
struct range_t hold;