Commit 95d55057 authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

Revert 3245 and 3246 because they cause valgrind failures.

TBR=lrn
Review URL: http://codereview.chromium.org/372059

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3254 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5ba34775
......@@ -49,7 +49,13 @@ StaticResource<Scanner::Utf8Decoder> Scanner::utf8_decoder_;
// ----------------------------------------------------------------------------
// UTF8Buffer
UTF8Buffer::UTF8Buffer() : data_(NULL), limit_(NULL) { }
UTF8Buffer::UTF8Buffer() {
static const int kInitialCapacity = 1 * KB;
data_ = NewArray<char>(kInitialCapacity);
limit_ = ComputeLimit(data_, kInitialCapacity);
Reset();
ASSERT(Capacity() == kInitialCapacity && pos() == 0);
}
UTF8Buffer::~UTF8Buffer() {
......@@ -63,7 +69,7 @@ void UTF8Buffer::AddCharSlow(uc32 c) {
int old_capacity = Capacity();
int old_position = pos();
int new_capacity =
Min(old_capacity * 3, old_capacity + kCapacityGrowthLimit);
Min(old_capacity * 2, old_capacity + kCapacityGrowthLimit);
char* new_data = NewArray<char>(new_capacity);
memcpy(new_data, data_, old_position);
DeleteArray(data_);
......@@ -340,6 +346,9 @@ void Scanner::Init(Handle<String> source, unibrow::CharacterStream* stream,
position_ = position;
// Reset literals buffer
literals_.Reset();
// Set c0_ (one character ahead)
ASSERT(kCharacterLookaheadBufferSize == 1);
Advance();
......@@ -367,7 +376,6 @@ Token::Value Scanner::Next() {
if (check.HasOverflowed()) {
stack_overflow_ = true;
next_.token = Token::ILLEGAL;
next_.literal_buffer = NULL;
} else {
Scan();
}
......@@ -376,23 +384,17 @@ Token::Value Scanner::Next() {
void Scanner::StartLiteral() {
// Use the first buffer unless it's currently in use by the current_ token.
// In most cases we won't have two literals/identifiers in a row, so
// the second buffer won't be used very often and is unlikely to grow much.
UTF8Buffer* free_buffer =
(current_.literal_buffer != &literal_buffer_1_) ? &literal_buffer_1_
: &literal_buffer_2_;
next_.literal_buffer = free_buffer;
free_buffer->Reset();
next_.literal_pos = literals_.pos();
}
void Scanner::AddChar(uc32 c) {
next_.literal_buffer->AddChar(c);
literals_.AddChar(c);
}
void Scanner::TerminateLiteral() {
next_.literal_end = literals_.pos();
AddChar(0);
}
......
......@@ -41,7 +41,6 @@ class UTF8Buffer {
~UTF8Buffer();
void AddChar(uc32 c) {
ASSERT_NOT_NULL(data_);
if (cursor_ <= limit_ &&
static_cast<unsigned>(c) <= unibrow::Utf8::kMaxOneByteChar) {
*cursor_++ = static_cast<char>(c);
......@@ -50,29 +49,16 @@ class UTF8Buffer {
}
}
void Reset() {
if (data_ == NULL) {
data_ = NewArray<char>(kInitialCapacity);
limit_ = ComputeLimit(data_, kInitialCapacity);
}
cursor_ = data_;
}
int pos() const {
ASSERT_NOT_NULL(data_);
return cursor_ - data_;
}
void Reset() { cursor_ = data_; }
int pos() const { return cursor_ - data_; }
char* data() const { return data_; }
private:
static const int kInitialCapacity = 256;
char* data_;
char* cursor_;
char* limit_;
int Capacity() const {
ASSERT_NOT_NULL(data_);
return (limit_ - data_) + unibrow::Utf8::kMaxEncodedSize;
}
......@@ -292,30 +278,26 @@ class Scanner {
// token returned by Next()). The string is 0-terminated and in
// UTF-8 format; they may contain 0-characters. Literal strings are
// collected for identifiers, strings, and numbers.
// These functions only give the correct result if the literal
// was scanned between calls to StartLiteral() and TerminateLiteral().
const char* literal_string() const {
return current_.literal_buffer->data();
return &literals_.data()[current_.literal_pos];
}
int literal_length() const {
// Excluding terminal '\0' added by TerminateLiteral().
return current_.literal_buffer->pos() - 1;
return current_.literal_end - current_.literal_pos;
}
Vector<const char> next_literal() const {
return Vector<const char>(next_literal_string(), next_literal_length());
}
// Returns the literal string for the next token (the token that
// would be returned if Next() were called).
const char* next_literal_string() const {
return next_.literal_buffer->data();
return &literals_.data()[next_.literal_pos];
}
// Returns the length of the next token (that would be returned if
// Next() were called).
int next_literal_length() const {
return next_.literal_buffer->pos() - 1;
}
Vector<const char> next_literal() const {
return Vector<const char>(next_literal_string(),
next_literal_length());
return next_.literal_end - next_.literal_pos;
}
// Scans the input as a regular expression pattern, previous
......@@ -357,8 +339,7 @@ class Scanner {
// Buffer to hold literal values (identifiers, strings, numbers)
// using 0-terminated UTF-8 encoding.
UTF8Buffer literal_buffer_1_;
UTF8Buffer literal_buffer_2_;
UTF8Buffer literals_;
bool stack_overflow_;
static StaticResource<Utf8Decoder> utf8_decoder_;
......@@ -370,7 +351,7 @@ class Scanner {
struct TokenDesc {
Token::Value token;
Location location;
UTF8Buffer* literal_buffer;
int literal_pos, literal_end;
};
TokenDesc current_; // desc for current token (as returned by Next())
......
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