From 0390fbf9784efc72c3f3c34fd55bd2312fa09f9f Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 3 Jun 2013 08:09:37 -0500 Subject: [PATCH] speedups --- common/dsnlexer.cpp | 96 +++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 56 deletions(-) diff --git a/common/dsnlexer.cpp b/common/dsnlexer.cpp index 6626fdacc3..d2b59b3faa 100644 --- a/common/dsnlexer.cpp +++ b/common/dsnlexer.cpp @@ -374,11 +374,11 @@ int DSNLEXER::NeedNUMBER( const char* aExpectation ) throw( IO_ERROR ) * i.e. no bytes with MSB on can be considered whitespace, since they are likely part * of a multibyte UTF8 character. */ -static bool isSpace( int cc ) +static bool isSpace( char cc ) { - // cc was signed extended from signed char, so it is often negative. + // cc is signed, so it is often negative. // Treat negative as large positive to exclude rapidly. - if( unsigned( cc ) <= ' ' ) + if( (unsigned char) cc <= ' ' ) { switch( cc ) { @@ -394,47 +394,41 @@ static bool isSpace( int cc ) } +inline bool isDigit( char cc ) +{ + return '0' <= cc && cc <= '9'; +} + + +/// return true if @a cc is an s-expression separator character +inline bool isSep( char cc ) +{ + return isSpace( cc ) || cc=='(' || cc==')'; +} + + /** * Function isNumber - * return true if the next sequence of s-expression text is a number: - * either an integer, fixed point, or float with exponent. + * returns true if the next sequence of text is a number: + * either an integer, fixed point, or float with exponent. Stops scanning + * at the first non-number character, even if it is not whitespace. * * @param cp is the start of the current token. * @param limit is the end of the current line of text. - * @param next is where to put a pointer to the start of the token after this one, but is only - * updated if the return value is true. - * @return bool - true if this is a number, else false. + * @return const char* - pointer to the start of the token after this one, but if + * this token is a number, else NULL */ -static bool isNumber( const char* cp, const char* limit, const char** next ) +static const char* isNumber( const char* cp, const char* limit ) { -#if 0 // no exponents supported - - if( strchr( "+-.0123456789", *cp ) ) - { - ++cp; - while( cp= limit ) { - wxString errtxt(_("Un-terminated delimited string") ); + wxString errtxt( _( "Un-terminated delimited string" ) ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } @@ -726,7 +710,7 @@ L_read: // If not, then call it a DSN_SYMBOL. { head = cur+1; - while( head