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

Side by Side Diff: src/value-serializer.cc

Issue 2549773002: Internalize strings in-place (Closed)
Patch Set: forgot one Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/value-serializer.h" 5 #include "src/value-serializer.h"
6 6
7 #include <type_traits> 7 #include <type_traits>
8 8
9 #include "src/base/logging.h" 9 #include "src/base/logging.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 return ReadHostObject(); 1118 return ReadHostObject();
1119 } 1119 }
1120 } 1120 }
1121 1121
1122 MaybeHandle<String> ValueDeserializer::ReadUtf8String() { 1122 MaybeHandle<String> ValueDeserializer::ReadUtf8String() {
1123 uint32_t utf8_length; 1123 uint32_t utf8_length;
1124 Vector<const uint8_t> utf8_bytes; 1124 Vector<const uint8_t> utf8_bytes;
1125 if (!ReadVarint<uint32_t>().To(&utf8_length) || 1125 if (!ReadVarint<uint32_t>().To(&utf8_length) ||
1126 utf8_length > 1126 utf8_length >
1127 static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) || 1127 static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) ||
1128 !ReadRawBytes(utf8_length).To(&utf8_bytes)) 1128 !ReadRawBytes(utf8_length).To(&utf8_bytes)) {
1129 return MaybeHandle<String>(); 1129 return MaybeHandle<String>();
1130 }
1130 return isolate_->factory()->NewStringFromUtf8( 1131 return isolate_->factory()->NewStringFromUtf8(
1131 Vector<const char>::cast(utf8_bytes), pretenure_); 1132 Vector<const char>::cast(utf8_bytes), pretenure_);
1132 } 1133 }
1133 1134
1134 MaybeHandle<String> ValueDeserializer::ReadTwoByteString() { 1135 MaybeHandle<String> ValueDeserializer::ReadTwoByteString() {
1135 uint32_t byte_length; 1136 uint32_t byte_length;
1136 Vector<const uint8_t> bytes; 1137 Vector<const uint8_t> bytes;
1137 if (!ReadVarint<uint32_t>().To(&byte_length) || 1138 if (!ReadVarint<uint32_t>().To(&byte_length) ||
1138 byte_length > 1139 byte_length >
1139 static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) || 1140 static_cast<uint32_t>(std::numeric_limits<int32_t>::max()) ||
1140 byte_length % sizeof(uc16) != 0 || !ReadRawBytes(byte_length).To(&bytes)) 1141 byte_length % sizeof(uc16) != 0 ||
1142 !ReadRawBytes(byte_length).To(&bytes)) {
1141 return MaybeHandle<String>(); 1143 return MaybeHandle<String>();
1144 }
1142 1145
1143 // Allocate an uninitialized string so that we can do a raw memcpy into the 1146 // Allocate an uninitialized string so that we can do a raw memcpy into the
1144 // string on the heap (regardless of alignment). 1147 // string on the heap (regardless of alignment).
1148 if (byte_length == 0) return isolate_->factory()->empty_string();
1145 Handle<SeqTwoByteString> string; 1149 Handle<SeqTwoByteString> string;
1146 if (!isolate_->factory() 1150 if (!isolate_->factory()
1147 ->NewRawTwoByteString(byte_length / sizeof(uc16), pretenure_) 1151 ->NewRawTwoByteString(byte_length / sizeof(uc16), pretenure_)
1148 .ToHandle(&string)) 1152 .ToHandle(&string)) {
1149 return MaybeHandle<String>(); 1153 return MaybeHandle<String>();
1154 }
1150 1155
1151 // Copy the bytes directly into the new string. 1156 // Copy the bytes directly into the new string.
1152 // Warning: this uses host endianness. 1157 // Warning: this uses host endianness.
1153 memcpy(string->GetChars(), bytes.begin(), bytes.length()); 1158 memcpy(string->GetChars(), bytes.begin(), bytes.length());
1154 return string; 1159 return string;
1155 } 1160 }
1156 1161
1157 bool ValueDeserializer::ReadExpectedString(Handle<String> expected) { 1162 bool ValueDeserializer::ReadExpectedString(Handle<String> expected) {
1158 // In the case of failure, the position in the stream is reset. 1163 // In the case of failure, the position in the stream is reset.
1159 const uint8_t* original_position = position_; 1164 const uint8_t* original_position = position_;
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 if (stack.size() != 1) { 1865 if (stack.size() != 1) {
1861 isolate_->Throw(*isolate_->factory()->NewError( 1866 isolate_->Throw(*isolate_->factory()->NewError(
1862 MessageTemplate::kDataCloneDeserializationError)); 1867 MessageTemplate::kDataCloneDeserializationError));
1863 return MaybeHandle<Object>(); 1868 return MaybeHandle<Object>();
1864 } 1869 }
1865 return scope.CloseAndEscape(stack[0]); 1870 return scope.CloseAndEscape(stack[0]);
1866 } 1871 }
1867 1872
1868 } // namespace internal 1873 } // namespace internal
1869 } // namespace v8 1874 } // namespace v8
OLDNEW
« src/objects-debug.cc ('K') | « 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