From: Wouter Wijngaards Date: Mon, 18 Feb 2008 15:45:14 +0000 (+0000) Subject: profiling speedups. X-Git-Tag: release-0.10~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db6178e670e26f4d25e7e70878f4e140a00675e4;p=thirdparty%2Funbound.git profiling speedups. git-svn-id: file:///svn/unbound/trunk@963 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index 29a8c1380..7ed3215de 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -8,6 +8,9 @@ - fixup iterator operating in no cache conditions (RD flag unset after a CNAME). - streamlined code for RD flag setting. + - profiled code and changed dname compares to be faster. + The speedup is about +3% to +8% (depending on the test). + - minievent tests for eintr and eagain. 15 February 2008: Wouter - added FreeBSD rc.d script to contrib. diff --git a/util/data/dname.c b/util/data/dname.c index 654b1c04f..1b7fa2950 100644 --- a/util/data/dname.c +++ b/util/data/dname.c @@ -91,10 +91,11 @@ dname_valid(uint8_t* dname, size_t maxlen) return len; } +/** compare uncompressed, noncanonical, registers are hints for speed */ int -query_dname_compare(uint8_t* d1, uint8_t* d2) +query_dname_compare(register uint8_t* d1, register uint8_t* d2) { - uint8_t lab1, lab2; + register uint8_t lab1, lab2; log_assert(d1 && d2); lab1 = *d1++; lab2 = *d2++; @@ -109,7 +110,9 @@ query_dname_compare(uint8_t* d1, uint8_t* d2) log_assert(lab1 == lab2 && lab1 != 0); /* compare lowercased labels. */ while(lab1--) { - if(tolower((int)*d1) != tolower((int)*d2)) { + /* compare bytes first for speed */ + if(*d1 != *d2 && + tolower((int)*d1) != tolower((int)*d2)) { if(tolower((int)*d1) < tolower((int)*d2)) return -1; return 1; @@ -259,16 +262,15 @@ dname_query_hash(uint8_t* dname, hashvalue_t h) int i; /* preserve case of query, make hash label by label */ - lablen = *dname; + lablen = *dname++; while(lablen) { log_assert(lablen <= LDNS_MAX_LABELLEN); labuf[0] = lablen; - dname++; i=0; while(lablen--) labuf[++i] = (uint8_t)tolower((int)*dname++); h = hashlittle(labuf, labuf[0] + 1, h); - lablen = *dname; + lablen = *dname++; } return h; @@ -407,11 +409,13 @@ static int memlowercmp(uint8_t* p1, uint8_t* p2, uint8_t len) { while(len--) { - if(tolower((int)*p1++) != tolower((int)*p2++)) { - if(tolower((int)p1[-1]) < tolower((int)p2[-1])) + if(*p1 != *p2 && tolower((int)*p1) != tolower((int)*p2)) { + if(tolower((int)*p1) < tolower((int)*p2)) return -1; return 1; } + p1++; + p2++; } return 0; } @@ -457,9 +461,7 @@ dname_lab_cmp(uint8_t* d1, int labs1, uint8_t* d2, int labs2, int* mlabs) else lastdiff = 1; lastmlabs = atlabel; } else if((c=memlowercmp(d1, d2, len1)) != 0) { - if(c<0) - lastdiff = -1; - else lastdiff = 1; + lastdiff = c; lastmlabs = atlabel; } diff --git a/util/mini_event.c b/util/mini_event.c index 10179264c..71726277a 100644 --- a/util/mini_event.c +++ b/util/mini_event.c @@ -165,6 +165,8 @@ static int handle_select(struct event_base* base, struct timeval* wait) memmove(&w, &base->writes, sizeof(fd_set)); if((ret = select(base->maxfd+1, &r, &w, NULL, wait)) == -1) { + if(errno == EAGAIN || errno == EINTR) + return 0; return -1; }