From 7978feebd2fb0be9f4a37980090dfebeeb29a36d Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 12 Sep 2007 17:02:55 +0000 Subject: [PATCH] pptok.c: quick-and-dirty downcasing during prehashing Speed up pptok.c by just doing |= 0x20 instead of calling tolower() for every character during prehashing. This is good enough for our needs, since we don't have any tokens containing the characters @ [ \ ] _ nor any high-bit characters (in which case we'd have to worry about multibyte anyway.) --- pptok.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pptok.pl b/pptok.pl index 99efc38..537705c 100755 --- a/pptok.pl +++ b/pptok.pl @@ -115,6 +115,12 @@ if ($what eq 'c') { foreach $pt (@pptok) { if (defined($pt)) { $tokens{'%'.$pt} = $n; + if ($pt =~ /[\@\[\]\\_]/) { + # Fail on characters which look like upper-case letters + # to the quick-and-dirty downcasing in the prehash + # (see below) + die "$in: invalid character in token: $pt"; + } } $n++; } @@ -183,7 +189,7 @@ if ($what eq 'c') { print OUT "\n"; print OUT " while ((c = *p++) != 0) {\n"; - print OUT " c = tolower(c);\n"; + print OUT " c |= 0x20; /* convert to lower case */\n"; printf OUT " uint32_t kn1 = rot(k1,%2d) - rot(k2,%2d) + c;\n", ${$sv}[0], ${$sv}[1]; printf OUT " uint32_t kn2 = rot(k2,%2d) - rot(k1,%2d) + c;\n", ${$sv}[2], ${$sv}[3]; print OUT " k1 = kn1; k2 = kn2;\n"; -- 2.7.4