[Webkit-unassigned] [Bug 70107] Custom written CSS lexer
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Mon Dec 12 13:28:18 PST 2011
https://bugs.webkit.org/show_bug.cgi?id=70107
--- Comment #13 from Oliver Hunt <oliver at apple.com> 2011-12-12 13:28:17 PST ---
(In reply to comment #12)
> Hey Oliver,
>
> actually the CSS parser working in an internal buffer, which is terminated by two '\0'-s, see the following code:
>
> void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
> {
> int length = string.length() + strlen(prefix) + strlen(suffix) + 2;
>
> fastFree(m_data);
> m_data = static_cast<UChar*>(fastMalloc(length * sizeof(UChar)));
> for (unsigned i = 0; i < strlen(prefix); i++)
> m_data[i] = prefix[i];
>
> memcpy(m_data + strlen(prefix), string.characters(), string.length() * sizeof(UChar));
>
> unsigned start = strlen(prefix) + string.length();
> unsigned end = start + strlen(suffix);
> for (unsigned i = start; i < end; i++)
> m_data[i] = suffix[i - start];
>
> m_data[length - 1] = 0;
> m_data[length - 2] = 0;
>
> yy_hold_char = 0;
> yyleng = 0;
> yytext = yy_c_buf_p = m_data;
> yy_hold_char = *yy_c_buf_p;
> resetRuleBodyMarks();
> }
>
> Flex needs this, and I actually liked this approach, since it requires less buffer range checks (you know that any non \0 character must be followed at least two \0-s). CSS actually designed that way that '\0' is not part of any token.
On the downside it requires a copy of the css source -- is a well predicted branch really more expensive than a copy?
--
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the webkit-unassigned
mailing list