Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(837)

Unified Diff: src/value-serializer.cc

Issue 2549773002: Internalize strings in-place (Closed)
Patch Set: rebased Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/s390/codegen-s390.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/value-serializer.cc
diff --git a/src/value-serializer.cc b/src/value-serializer.cc
index c757650d04f44cb0d0b0b3f657b007e929001d3e..effbe3f0b68e2fc6a60d191b4e94a57a29e85d0c 100644
--- a/src/value-serializer.cc
+++ b/src/value-serializer.cc
@@ -1136,8 +1136,9 @@ MaybeHandle<String> ValueDeserializer::ReadUtf8String() {
if (!ReadVarint<uint32_t>().To(&utf8_length) ||
utf8_length >
static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) ||
- !ReadRawBytes(utf8_length).To(&utf8_bytes))
+ !ReadRawBytes(utf8_length).To(&utf8_bytes)) {
return MaybeHandle<String>();
+ }
return isolate_->factory()->NewStringFromUtf8(
Vector<const char>::cast(utf8_bytes), pretenure_);
}
@@ -1148,16 +1149,20 @@ MaybeHandle<String> ValueDeserializer::ReadTwoByteString() {
if (!ReadVarint<uint32_t>().To(&byte_length) ||
byte_length >
static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) ||
- byte_length % sizeof(uc16) != 0 || !ReadRawBytes(byte_length).To(&bytes))
+ byte_length % sizeof(uc16) != 0 ||
+ !ReadRawBytes(byte_length).To(&bytes)) {
return MaybeHandle<String>();
+ }
// Allocate an uninitialized string so that we can do a raw memcpy into the
// string on the heap (regardless of alignment).
+ if (byte_length == 0) return isolate_->factory()->empty_string();
Handle<SeqTwoByteString> string;
if (!isolate_->factory()
->NewRawTwoByteString(byte_length / sizeof(uc16), pretenure_)
- .ToHandle(&string))
+ .ToHandle(&string)) {
return MaybeHandle<String>();
+ }
// Copy the bytes directly into the new string.
// Warning: this uses host endianness.
« no previous file with comments | « src/s390/codegen-s390.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698