Author: jmb
Date: Sun Nov 30 16:16:10 2008
New Revision: 5855
URL:
http://source.netsurf-browser.org?rev=5855&view=rev
Log:
Make getToken reduce consecutive whitespace tokens to a single whitespace token.
Update eatWS appropriately. This reduces the number of calls to getToken by a million or
so.
Modified:
trunk/libcss/src/parse/parse.c
Modified: trunk/libcss/src/parse/parse.c
URL:
http://source.netsurf-browser.org/trunk/libcss/src/parse/parse.c?rev=5855...
==============================================================================
--- trunk/libcss/src/parse/parse.c (original)
+++ trunk/libcss/src/parse/parse.c Sun Nov 30 16:16:10 2008
@@ -102,6 +102,8 @@
uint8_t match_char; /**< Close bracket type for parseAny */
+ bool last_was_ws; /**< Last token was whitespace */
+
css_parser_event_handler event; /**< Client's event handler */
void *event_pw; /**< Client data for event handler */
@@ -266,6 +268,7 @@
p->parseError = false;
p->match_char = 0;
p->event = NULL;
+ p->last_was_ws = false;
p->event_pw = NULL;
p->alloc = alloc;
p->pw = pw;
@@ -568,6 +571,14 @@
error = css_lexer_get_token(parser->lexer, &t);
if (error != CSS_OK)
return error;
+
+ /* If the last token read was whitespace, keep reading
+ * tokens until we encounter one that isn't whitespace */
+ while (parser->last_was_ws && t->type == CSS_TOKEN_S) {
+ error = css_lexer_get_token(parser->lexer, &t);
+ if (error != CSS_OK)
+ return error;
+ }
/** \todo We need only intern for the following token types:
*
@@ -662,6 +673,8 @@
if (perror != PARSERUTILS_OK)
return css_error_from_parserutils_error(perror);
+ parser->last_was_ws = ((*token)->type == CSS_TOKEN_S);
+
return CSS_OK;
}
@@ -699,17 +712,14 @@
const css_token *token;
css_error error;
- while (1) {
- error = getToken(parser, &token);
- if (error != CSS_OK)
- return error;
-
- if (token->type != CSS_TOKEN_S) {
- error = pushBack(parser, token);
- if (error != CSS_OK)
- return error;
- break;
- }
+ error = getToken(parser, &token);
+ if (error != CSS_OK)
+ return error;
+
+ if (token->type != CSS_TOKEN_S) {
+ error = pushBack(parser, token);
+ if (error != CSS_OK)
+ return error;
}
return CSS_OK;