From ed26897d2312ed8aebd234b6e47b4319c56dd083 Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Wed, 8 Jun 2016 22:13:41 +0000 Subject: Third optimization, use short type, which is the smallest functional int which requires 1. no unsigned -> signed promotion, 2. fetches from a word aligned offset from the lookup table, 3. is easily promoted to int upon the function's return. This introduces a very small 2% speed improvement in several cases. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1747460 13f79535-47bb-0310-9956-ffa450edef68 --- strings/apr_cstr.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'strings') diff --git a/strings/apr_cstr.c b/strings/apr_cstr.c index fb940c42c..a79bf0f61 100644 --- a/strings/apr_cstr.c +++ b/strings/apr_cstr.c @@ -196,7 +196,7 @@ char * apr_cstr_join(const apr_array_header_t *strings, * octets (such as extended latin alphabetics) are never case-folded. * NOTE: Other than Alpha A-Z/a-z, each code point is unique! */ -static const unsigned char ucharmap[] = { +static const short ucharmap[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, @@ -243,7 +243,7 @@ static const unsigned char ucharmap[] = { * * NOTE: Other than Alpha A-Z/a-z, each code point is unique! */ -static const unsigned char ucharmap[] = { +static const short ucharmap[] = { 0x00, 0x01, 0x02, 0x03, 0x9C, 0x09, 0x86, 0x7F, 0x97, 0x8D, 0x8E, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x9D, 0x85, 0x08, 0x87, @@ -283,9 +283,9 @@ int apr_cstr_casecmp(const char *str1, const char *str2) { for (;;) { - const int c1 = (int)(*((const unsigned char *)str1)); - const int c2 = (int)(*((const unsigned char *)str2)); - const int cmp = ucharmap[c1] - ucharmap[c2]; + const short c1 = (short)(*((const unsigned char *)str1)); + const short c2 = (short)(*((const unsigned char *)str2)); + const short cmp = ucharmap[c1] - ucharmap[c2]; /* Not necessary to test for !c2, this is caught by cmp */ if (cmp || !c1) return cmp; @@ -298,9 +298,9 @@ int apr_cstr_casecmpn(const char *str1, const char *str2, apr_size_t n) { while (n--) { - const int c1 = (int)(*((const unsigned char *)str1)); - const int c2 = (int)(*((const unsigned char *)str2)); - const int cmp = ucharmap[c1] - ucharmap[c2]; + const short c1 = (short)(*((const unsigned char *)str1)); + const short c2 = (short)(*((const unsigned char *)str2)); + const short cmp = ucharmap[c1] - ucharmap[c2]; /* Not necessary to test for !c2, this is caught by cmp */ if (cmp || !c1) return cmp; -- cgit v1.2.1