From ef543fb112c69bc877a1d0b22823d9e07c7ab05b Mon Sep 17 00:00:00 2001 From: yaworsky Date: Tue, 15 Nov 2005 12:36:44 +0000 Subject: Optimized for speed parsing the month field --- daemon/syslogd.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 7 deletions(-) diff --git a/daemon/syslogd.c b/daemon/syslogd.c index da53e60..99e9a92 100644 --- a/daemon/syslogd.c +++ b/daemon/syslogd.c @@ -390,6 +390,102 @@ no_pri: return msg; } +/****************************************************************************** + * str2month + * + * return month (1..12) or 0 if error + */ +static int str2month( char* s ) +{ + register char s1, s2, s3; + + s1 = s[0]; + if( 'A' <= s[0] && s[0] <= 'Z' ) + s1 += 'a' - 'A'; + + s2 = s[1]; + if( 'A' <= s[1] && s[1] <= 'Z' ) + s2 += 'a' - 'A'; + + s3 = s[2]; + if( 'A' <= s[2] && s[2] <= 'Z' ) + s3 += 'a' - 'A'; + + if( s1 < 'm' ) + { + if( s1 < 'f' ) + { + if( s1 == 'a' ) + { + if( s2 == 'p' && s3 == 'r' ) + return 4; /* Apr */ + if( s2 == 'u' && s3 == 'g' ) + return 8; /* Aug */ + return 0; + } + else if( s1 == 'd' ) + { + if( s2 == 'e' && s3 == 'c' ) + return 12; /* Dec */ + return 0; + } + else + return 0; + } + else if( s1 == 'f' ) + { + if( s2 == 'e' && s3 == 'b' ) + return 2; /* Feb */ + return 0; + } + else if( s1 == 'j' ) + { + if( s2 == 'a' && s3 == 'n' ) + return 1; /* Jan */ + if( s2 != 'u' ) + return 0; + if( s3 == 'l' ) + return 7; /* Jul */ + if( s3 == 'n' ) + return 6; /* Jun */ + return 0; + } + else + return 0; + } + else if( s1 > 'm' ) + { + if( s1 < 'o' ) + { + if( s1 == 'n' && s2 == 'o' && s3 == 'v' ) + return 11; /* Nov */ + return 0; + } + else if( s1 > 'o' ) + { + if( s1 == 's' && s2 == 'e' && s3 == 'p' ) + return 9; /* Sep */ + return 0; + } + else /* s1 == 'o' */ + { + if( s2 == 'c' && s3 == 't' ) + return 10; /* Oct */ + return 0; + } + } + else /* s1 == 'm' */ + { + if( s2 != 'a' ) + return 0; + if( s3 == 'r' ) + return 3; /* Mar */ + if( s3 == 'y' ) + return 5; /* May */ + return 0; + } +} + /****************************************************************************** * parse_timestamp * @@ -398,16 +494,11 @@ no_pri: */ static gchar* parse_timestamp( gchar* msg, LPSYSTEMTIME timestamp ) { - int i; - TRACE_ENTER( "\n" ); - for( i = 0; i < 12; i++ ) - if( strncasecmp( msg, str_month[ i ], 3 ) == 0 ) - break; - if( i == 12 ) + timestamp->wMonth = str2month( msg ); + if( 0 == timestamp->wMonth ) goto no_timestamp; - timestamp->wMonth = i + 1; if( msg[3] != ' ' ) goto no_timestamp; -- cgit v1.2.3