Commit 43cddf41 authored by kasperl@chromium.org's avatar kasperl@chromium.org

Optimize the lexical scanner by selective inlining, and

by dealing with whitespace as part of the token scanning
instead of as a separate step before it.
Review URL: http://codereview.chromium.org/113336

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1934 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ae8e20ba
This diff is collapsed.
...@@ -39,16 +39,33 @@ class UTF8Buffer { ...@@ -39,16 +39,33 @@ class UTF8Buffer {
UTF8Buffer(); UTF8Buffer();
~UTF8Buffer(); ~UTF8Buffer();
void Initialize(char* src, int length); void AddChar(uc32 c) {
void AddChar(uc32 c); if (cursor_ <= limit_ &&
void Reset() { pos_ = 0; } static_cast<unsigned>(c) <= unibrow::Utf8::kMaxOneByteChar) {
int pos() const { return pos_; } *cursor_++ = static_cast<char>(c);
} else {
AddCharSlow(c);
}
}
void Reset() { cursor_ = data_; }
int pos() const { return cursor_ - data_; }
char* data() const { return data_; } char* data() const { return data_; }
private: private:
char* data_; char* data_;
int size_; char* cursor_;
int pos_; char* limit_;
int Capacity() const {
return (limit_ - data_) + unibrow::Utf8::kMaxEncodedSize;
}
static char* ComputeLimit(char* data, int capacity) {
return (data + capacity) - unibrow::Utf8::kMaxEncodedSize;
}
void AddCharSlow(uc32 c);
}; };
...@@ -204,7 +221,7 @@ class Scanner { ...@@ -204,7 +221,7 @@ class Scanner {
void Advance(); void Advance();
void PushBack(uc32 ch); void PushBack(uc32 ch);
void SkipWhiteSpace(bool initial); bool SkipWhiteSpace();
Token::Value SkipSingleLineComment(); Token::Value SkipSingleLineComment();
Token::Value SkipMultiLineComment(); Token::Value SkipMultiLineComment();
...@@ -212,7 +229,6 @@ class Scanner { ...@@ -212,7 +229,6 @@ class Scanner {
inline Token::Value Select(uc32 next, Token::Value then, Token::Value else_); inline Token::Value Select(uc32 next, Token::Value then, Token::Value else_);
void Scan(); void Scan();
Token::Value ScanToken();
void ScanDecimalDigits(); void ScanDecimalDigits();
Token::Value ScanNumber(bool seen_period); Token::Value ScanNumber(bool seen_period);
Token::Value ScanIdentifier(); Token::Value ScanIdentifier();
......
...@@ -197,7 +197,7 @@ namespace v8 { namespace internal { ...@@ -197,7 +197,7 @@ namespace v8 { namespace internal {
T(ILLEGAL, "ILLEGAL", 0) \ T(ILLEGAL, "ILLEGAL", 0) \
\ \
/* Scanner-internal use only. */ \ /* Scanner-internal use only. */ \
T(COMMENT, NULL, 0) T(WHITESPACE, NULL, 0)
class Token { class Token {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment