[Xastir-dev] Awk.c optimization
John Laxson
jlaxson at mac.com
Sun May 1 11:33:12 EDT 2005
Looking at it a little further, checking for case-insensitive first
character is redundant, because strncmp() is case sensitive. That
may be unintended as-is, but to use strcasecmp() would probably slow
down map drawing beyond what it is now. So, having avoided the whole
issue of charset-specific translation, here is my final version.
- John Laxson
Index: awk.c
===================================================================
RCS file: /cvsroot/xastir/xastir/src/awk.c,v
retrieving revision 1.25
diff -u -r1.25 awk.c
--- awk.c 8 Jan 2005 10:06:51 -0000 1.25
+++ awk.c 1 May 2005 15:24:42 -0000
@@ -169,9 +168,6 @@
}
-
-
-
/*
* awk_find_sym: search symtab for symbol
*/
@@ -179,14 +175,11 @@
const char *name,
const int len) {
awk_symbol *s;
- char c, d;
-
+ char c;
- // Create holding spot for both cases of first character, in
- // order to speed up the loop below.
- c = toupper(name[0]);
- d = name[0];
+ c = name[0];
+
// Check through the hash
//
for (s = this->hash[AWK_SYM_HASH(name,len)]; s; s = s->next_sym) {
@@ -195,11 +188,13 @@
if (s->namelen == len) {
// Check first chars next (fast operation)
- if (s->name[0] == c || s->name[0] == d) {
+ if (s->name[0] == c) {
// Ok so far, test the entire string (slow
- // operation)
- if (strncmp(s->name,name,len) == 0)
+ // operation, case sensitive)
+ if (len == 1)
+ return s;
+ if (len > 1 && strncmp(s->name+1,name+1,len-1) == 0)
return s;
}
}
More information about the Xastir-dev
mailing list