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

Side by Side Diff: src/heap/heap-inl.h

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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_HEAP_HEAP_INL_H_ 5 #ifndef V8_HEAP_HEAP_INL_H_
6 #define V8_HEAP_HEAP_INL_H_ 6 #define V8_HEAP_HEAP_INL_H_
7 7
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (IsOneByte(t, chars)) { 217 if (IsOneByte(t, chars)) {
218 return AllocateInternalizedStringImpl<true>(t, chars, hash_field); 218 return AllocateInternalizedStringImpl<true>(t, chars, hash_field);
219 } 219 }
220 return AllocateInternalizedStringImpl<false>(t, chars, hash_field); 220 return AllocateInternalizedStringImpl<false>(t, chars, hash_field);
221 } 221 }
222 222
223 223
224 AllocationResult Heap::AllocateOneByteInternalizedString( 224 AllocationResult Heap::AllocateOneByteInternalizedString(
225 Vector<const uint8_t> str, uint32_t hash_field) { 225 Vector<const uint8_t> str, uint32_t hash_field) {
226 CHECK_GE(String::kMaxLength, str.length()); 226 CHECK_GE(String::kMaxLength, str.length());
227 // The canonical empty_string is the only zero-length string we allow.
228 DCHECK_IMPLIES(str.length() == 0, roots_[kempty_stringRootIndex] == nullptr);
227 // Compute map and object size. 229 // Compute map and object size.
228 Map* map = one_byte_internalized_string_map(); 230 Map* map = one_byte_internalized_string_map();
229 int size = SeqOneByteString::SizeFor(str.length()); 231 int size = SeqOneByteString::SizeFor(str.length());
230 232
231 // Allocate string. 233 // Allocate string.
232 HeapObject* result = nullptr; 234 HeapObject* result = nullptr;
233 { 235 {
234 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); 236 AllocationResult allocation = AllocateRaw(size, OLD_SPACE);
235 if (!allocation.To(&result)) return allocation; 237 if (!allocation.To(&result)) return allocation;
236 } 238 }
(...skipping 11 matching lines...) Expand all
248 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(), 250 MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(),
249 str.length()); 251 str.length());
250 252
251 return answer; 253 return answer;
252 } 254 }
253 255
254 256
255 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str, 257 AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str,
256 uint32_t hash_field) { 258 uint32_t hash_field) {
257 CHECK_GE(String::kMaxLength, str.length()); 259 CHECK_GE(String::kMaxLength, str.length());
260 DCHECK_NE(0, str.length()); // Use Heap::empty_string() instead.
258 // Compute map and object size. 261 // Compute map and object size.
259 Map* map = internalized_string_map(); 262 Map* map = internalized_string_map();
260 int size = SeqTwoByteString::SizeFor(str.length()); 263 int size = SeqTwoByteString::SizeFor(str.length());
261 264
262 // Allocate string. 265 // Allocate string.
263 HeapObject* result = nullptr; 266 HeapObject* result = nullptr;
264 { 267 {
265 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); 268 AllocationResult allocation = AllocateRaw(size, OLD_SPACE);
266 if (!allocation.To(&result)) return allocation; 269 if (!allocation.To(&result)) return allocation;
267 } 270 }
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 859
857 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { 860 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) {
858 for (Object** current = start; current < end; current++) { 861 for (Object** current = start; current < end; current++) {
859 CHECK((*current)->IsSmi()); 862 CHECK((*current)->IsSmi());
860 } 863 }
861 } 864 }
862 } // namespace internal 865 } // namespace internal
863 } // namespace v8 866 } // namespace v8
864 867
865 #endif // V8_HEAP_HEAP_INL_H_ 868 #endif // V8_HEAP_HEAP_INL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698