Reviewers: marja,
Message:
Committed patchset #2 manually as r20007 (presubmit successful).
Description:
Experimental parser: small fixes
[email protected]
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=20007
Please review this at https://codereview.chromium.org/201953002/
SVN Base: https://v8.googlecode.com/svn/branches/experimental/parser
Affected files (+29, -30 lines):
M src/factory.h
M src/factory.cc
M src/heap.h
M src/heap.cc
M src/lexer/lexer-shell.cc
M src/lexer/lexer.cc
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index
6f86647ef5911348cda4fa55bb590e39d4334b27..0f4ef0676536226011c9d4668052d35be14bf2ab
100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -272,10 +272,12 @@ Handle<String>
Factory::NewStringFromUtf8(Vector<const char> string,
Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
+ bool check_for_one_byte,
PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(
isolate(),
- isolate()->heap()->AllocateStringFromTwoByte(string, pretenure),
+ isolate()->heap()->AllocateStringFromTwoByte(
+ string, check_for_one_byte, pretenure),
String);
}
Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index
558ff85a983c957d37b9bed14b1a24227a3586d5..3f27ace70995baf7e01ba831a617ba0570ac54a2
100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -149,6 +149,7 @@ class Factory {
Handle<String> NewStringFromTwoByte(
Vector<const uc16> str,
+ bool check_for_one_byte = true,
PretenureFlag pretenure = NOT_TENURED);
// Allocates and partially initializes an ASCII or TwoByte String. The
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index
aa5c3a9200cdfeecfad159ed9af42970ec2dc983..14c826481b049bfe4b6ed6deac9da6e7439fe40f
100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -4811,13 +4811,14 @@ MaybeObject*
Heap::AllocateStringFromUtf8Slow(Vector<const char> string,
MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
+ bool check_for_one_byte,
PretenureFlag pretenure) {
// Check if the string is an ASCII string.
Object* result;
int length = string.length();
const uc16* start = string.start();
- if (String::IsOneByte(start, length)) {
+ if (check_for_one_byte && String::IsOneByte(start, length)) {
MaybeObject* maybe_result = AllocateRawOneByteString(length,
pretenure);
if (!maybe_result->ToObject(&result)) return maybe_result;
CopyChars(SeqOneByteString::cast(result)->GetChars(), start, length);
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index
304e1f86f0dffb70cc26f5d2eeab285cb1ae4a2a..369352b7758f4ccdace0c54f81f37a090416b3df
100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -868,6 +868,7 @@ class Heap {
PretenureFlag pretenure = NOT_TENURED);
MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte(
Vector<const uc16> str,
+ bool check_for_one_byte,
PretenureFlag pretenure = NOT_TENURED);
// Allocates an internalized string in old space based on the character
Index: src/lexer/lexer-shell.cc
diff --git a/src/lexer/lexer-shell.cc b/src/lexer/lexer-shell.cc
index
b180a6681804f1f1f71ac92a80f5299eda006ad5..c44528819ff41fdbe4e8f2e2df39ac8a0b11df72
100644
--- a/src/lexer/lexer-shell.cc
+++ b/src/lexer/lexer-shell.cc
@@ -96,11 +96,11 @@ static uint16_t* ConvertUtf8ToUtf16(const uint16_t*
const data_in,
if (c <= unibrow::Utf8::kMaxOneByteChar) {
position++;
} else {
- *is_one_byte = false;
c = unibrow::Utf8::CalculateValue(char_data + position,
file_size - position,
&position);
}
+ if (c > unibrow::Latin1::kMaxChar) *is_one_byte = false;
if (c > kMaxUtf16Character) {
utf16_chars += 2;
} else {
@@ -224,30 +224,8 @@ static bool HasLiteral(Token::Value token) {
}
-template<typename Char>
-static void Copy(const Vector<Char>& literal,
- SmartArrayPointer<const uint16_t>* result,
- int* literal_length) {
- uint16_t* data = new uint16_t[literal.length()];
- result->Reset(data);
- for (int i = 0; i < literal.length(); i++) {
- data[i] = literal[i];
- }
- *literal_length = literal.length();
-}
-
-
class TokenWithLocation {
public:
- Token::Value value;
- int beg;
- int end;
- bool is_one_byte;
- SmartArrayPointer<const uint16_t> literal;
- int literal_length;
- // The location of the latest octal position when the token was seen.
- int octal_beg;
- int octal_end;
TokenWithLocation(Token::Value token,
Scanner* scanner,
Handle<String> literal_string)
@@ -261,10 +239,15 @@ class TokenWithLocation {
if (!literal_string.is_null()) {
DisallowHeapAllocation no_alloc;
String::FlatContent content = literal_string->GetFlatContent();
+ literal_length = literal_string->length();
+ literal.Reset(new uint16_t[literal_length]);
if (content.IsAscii()) {
- Copy(content.ToOneByteVector(), &literal, &literal_length);
+ is_one_byte = true;
+ CopyChars(
+ literal.get(), content.ToOneByteVector().start(),
literal_length);
} else {
- Copy(content.ToUC16Vector(), &literal, &literal_length);
+ CopyChars(
+ literal.get(), content.ToUC16Vector().start(), literal_length);
}
}
}
@@ -274,7 +257,7 @@ class TokenWithLocation {
return;
}
printf("%-15s (%d, %d)", Token::Name(value), beg, end);
- if (literal_length > 0) {
+ if (literal.get() != NULL) {
// TODO(dcarney): need some sort of checksum.
for (int i = 0; i < literal_length; i++) {
printf(is_one_byte ? " %02x" : " %04x", literal[i]);
@@ -288,6 +271,16 @@ class TokenWithLocation {
}
private:
+ Token::Value value;
+ int beg;
+ int end;
+ bool is_one_byte;
+ SmartArrayPointer<uint16_t> literal;
+ int literal_length;
+ // The location of the latest octal position when the token was seen.
+ int octal_beg;
+ int octal_end;
+
DISALLOW_COPY_AND_ASSIGN(TokenWithLocation);
};
@@ -307,7 +300,7 @@ static TimeDelta RunLexer(const uint16_t* source,
case UTF16: {
CHECK_EQ(0, bytes % 2);
Handle<String> result = isolate->factory()->NewStringFromTwoByte(
- Vector<const uint16_t>(source, bytes / 2));
+ Vector<const uint16_t>(source, bytes / 2), false);
stream.Reset(
new GenericStringUtf16CharacterStream(result, 0,
result->length()));
break;
Index: src/lexer/lexer.cc
diff --git a/src/lexer/lexer.cc b/src/lexer/lexer.cc
index
9140f99b5be1f9e801af2961e5f7b953cbff18f4..4c565a060a8f72a88d3398bc575709a642534f4a
100644
--- a/src/lexer/lexer.cc
+++ b/src/lexer/lexer.cc
@@ -737,7 +737,8 @@ Handle<String>
Lexer<Char>::AllocateNextLiteralString(Isolate* isolate,
EnsureLiteralIsValid(token, literal);
return literal->is_one_byte() ?
factory->NewStringFromOneByte(literal->one_byte_string(),
tenured) :
- factory->NewStringFromTwoByte(literal->two_byte_string(), tenured);
+ factory->NewStringFromTwoByte(
+ literal->two_byte_string(), false, tenured);
}
int offset = 0, length = 0;
LiteralOffsetAndLength<Char>(buffer_, token, &offset, &length);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.