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

Side by Side Diff: src/heap.cc

Issue 11649018: Remove Utf8InputBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « src/debug-agent.cc ('k') | src/objects.h » ('j') | src/objects.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4527 matching lines...) Expand 10 before | Expand all | Expand 10 after
4538 CopyChars(SeqOneByteString::cast(result)->GetChars(), string.start(), length); 4538 CopyChars(SeqOneByteString::cast(result)->GetChars(), string.start(), length);
4539 return result; 4539 return result;
4540 } 4540 }
4541 4541
4542 4542
4543 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string, 4543 MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string,
4544 int non_ascii_start, 4544 int non_ascii_start,
4545 PretenureFlag pretenure) { 4545 PretenureFlag pretenure) {
4546 // Continue counting the number of characters in the UTF-8 string, starting 4546 // Continue counting the number of characters in the UTF-8 string, starting
4547 // from the first non-ascii character or word. 4547 // from the first non-ascii character or word.
4548 int chars = non_ascii_start;
4549 Access<UnicodeCache::Utf8Decoder> 4548 Access<UnicodeCache::Utf8Decoder>
4550 decoder(isolate_->unicode_cache()->utf8_decoder()); 4549 decoder(isolate_->unicode_cache()->utf8_decoder());
4551 decoder->Reset(string.start() + non_ascii_start, string.length() - chars); 4550 decoder->Reset(string.start() + non_ascii_start,
4552 while (decoder->has_more()) { 4551 string.length() - non_ascii_start);
4553 uint32_t r = decoder->GetNext(); 4552 int utf16_length = decoder->Utf16Length();
4554 if (r <= unibrow::Utf16::kMaxNonSurrogateCharCode) { 4553 ASSERT(utf16_length > 0);
4555 chars++; 4554 // Allocate string.
4556 } else { 4555 Object* result;
4557 chars += 2; 4556 {
4557 int chars = non_ascii_start + utf16_length;
4558 MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure);
4559 if (!maybe_result->ToObject(&result)) return maybe_result;
4560 }
4561 // Convert and copy the characters into the new object.
4562 SeqTwoByteString* twobyte = SeqTwoByteString::cast(result);
4563 // Copy ascii portion.
4564 uint16_t* data = twobyte->GetChars();
4565 if (non_ascii_start != 0) {
4566 const char* ascii_data = string.start();
4567 for (int i = 0; i < non_ascii_start; i++) {
4568 *data++ = *ascii_data++;
4558 } 4569 }
4559 } 4570 }
4560 4571 // Now write the remainder.
4561 Object* result; 4572 decoder->WriteUtf16(data, utf16_length);
4562 { MaybeObject* maybe_result = AllocateRawTwoByteString(chars, pretenure);
4563 if (!maybe_result->ToObject(&result)) return maybe_result;
4564 }
4565
4566 // Convert and copy the characters into the new object.
4567 SeqTwoByteString* twobyte = SeqTwoByteString::cast(result);
4568 decoder->Reset(string.start(), string.length());
4569 int i = 0;
4570 while (i < chars) {
4571 uint32_t r = decoder->GetNext();
4572 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) {
4573 twobyte->SeqTwoByteStringSet(i++, unibrow::Utf16::LeadSurrogate(r));
4574 twobyte->SeqTwoByteStringSet(i++, unibrow::Utf16::TrailSurrogate(r));
4575 } else {
4576 twobyte->SeqTwoByteStringSet(i++, r);
4577 }
4578 }
4579 return result; 4573 return result;
4580 } 4574 }
4581 4575
4582 4576
4583 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string, 4577 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
4584 PretenureFlag pretenure) { 4578 PretenureFlag pretenure) {
4585 // Check if the string is an ASCII string. 4579 // Check if the string is an ASCII string.
4586 Object* result; 4580 Object* result;
4587 int length = string.length(); 4581 int length = string.length();
4588 const uc16* start = string.start(); 4582 const uc16* start = string.start();
(...skipping 2884 matching lines...) Expand 10 before | Expand all | Expand 10 after
7473 static_cast<int>(object_sizes_last_time_[index])); 7467 static_cast<int>(object_sizes_last_time_[index]));
7474 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT) 7468 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
7475 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7469 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7476 7470
7477 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7471 memcpy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7478 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7472 memcpy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7479 ClearObjectStats(); 7473 ClearObjectStats();
7480 } 7474 }
7481 7475
7482 } } // namespace v8::internal 7476 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug-agent.cc ('k') | src/objects.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698