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

Side by Side Diff: src/objects.cc

Issue 228093004: Implement handlified String::Flatten. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: even shorter Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 return true; // An Ape, an ABCBook. 1175 return true; // An Ape, an ABCBook.
1176 } else if ((c1 == 0 || (c1 >= 'A' && c1 <= 'Z')) && 1176 } else if ((c1 == 0 || (c1 >= 'A' && c1 <= 'Z')) &&
1177 (c0 == 'F' || c0 == 'H' || c0 == 'M' || c0 == 'N' || c0 == 'R' || 1177 (c0 == 'F' || c0 == 'H' || c0 == 'M' || c0 == 'N' || c0 == 'R' ||
1178 c0 == 'S' || c0 == 'X')) { 1178 c0 == 'S' || c0 == 'X')) {
1179 return true; // An MP3File, an M. 1179 return true; // An MP3File, an M.
1180 } 1180 }
1181 return false; 1181 return false;
1182 } 1182 }
1183 1183
1184 1184
1185 Handle<String> String::SlowFlatten(Handle<ConsString> cons,
1186 PretenureFlag pretenure) {
1187 ASSERT(AllowHeapAllocation::IsAllowed());
1188 ASSERT(cons->second()->length() != 0);
1189 Isolate* isolate = cons->GetIsolate();
1190 int length = cons->length();
1191 PretenureFlag tenure = isolate->heap()->InNewSpace(*cons) ? pretenure
1192 : TENURED;
1193 Handle<SeqString> result;
1194 if (cons->IsOneByteRepresentation()) {
1195 Handle<SeqOneByteString> flat = isolate->factory()->NewRawOneByteString(
1196 length, tenure).ToHandleChecked();
1197 DisallowHeapAllocation no_gc;
1198 WriteToFlat(*cons, flat->GetChars(), 0, length);
1199 result = flat;
1200 } else {
1201 Handle<SeqTwoByteString> flat = isolate->factory()->NewRawTwoByteString(
1202 length, tenure).ToHandleChecked();
1203 DisallowHeapAllocation no_gc;
1204 WriteToFlat(*cons, flat->GetChars(), 0, length);
1205 result = flat;
1206 }
1207 cons->set_first(*result);
1208 cons->set_second(isolate->heap()->empty_string());
1209 return result;
1210 }
1211
1212
1185 MaybeObject* String::SlowTryFlatten(PretenureFlag pretenure) { 1213 MaybeObject* String::SlowTryFlatten(PretenureFlag pretenure) {
1186 #ifdef DEBUG 1214 #ifdef DEBUG
1187 // Do not attempt to flatten in debug mode when allocation is not 1215 // Do not attempt to flatten in debug mode when allocation is not
1188 // allowed. This is to avoid an assertion failure when allocating. 1216 // allowed. This is to avoid an assertion failure when allocating.
1189 // Flattening strings is the only case where we always allow 1217 // Flattening strings is the only case where we always allow
1190 // allocation because no GC is performed if the allocation fails. 1218 // allocation because no GC is performed if the allocation fails.
1191 if (!AllowHeapAllocation::IsAllowed()) return this; 1219 if (!AllowHeapAllocation::IsAllowed()) return this;
1192 #endif 1220 #endif
1193 1221
1194 Heap* heap = GetHeap(); 1222 Heap* heap = GetHeap();
(...skipping 5186 matching lines...) Expand 10 before | Expand all | Expand 10 after
6381 attributes, 6409 attributes,
6382 access_control); 6410 access_control);
6383 return; 6411 return;
6384 } 6412 }
6385 6413
6386 // Make sure that the top context does not change when doing callbacks or 6414 // Make sure that the top context does not change when doing callbacks or
6387 // interceptor calls. 6415 // interceptor calls.
6388 AssertNoContextChange ncc(isolate); 6416 AssertNoContextChange ncc(isolate);
6389 6417
6390 // Try to flatten before operating on the string. 6418 // Try to flatten before operating on the string.
6391 if (name->IsString()) String::cast(*name)->TryFlatten(); 6419 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
6392 6420
6393 if (!JSObject::CanSetCallback(object, name)) return; 6421 if (!JSObject::CanSetCallback(object, name)) return;
6394 6422
6395 uint32_t index = 0; 6423 uint32_t index = 0;
6396 bool is_element = name->AsArrayIndex(&index); 6424 bool is_element = name->AsArrayIndex(&index);
6397 6425
6398 Handle<Object> old_value = isolate->factory()->the_hole_value(); 6426 Handle<Object> old_value = isolate->factory()->the_hole_value();
6399 bool is_observed = object->map()->is_observed() && 6427 bool is_observed = object->map()->is_observed() &&
6400 *name != isolate->heap()->hidden_string(); 6428 *name != isolate->heap()->hidden_string();
6401 bool preexists = false; 6429 bool preexists = false;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
6569 if (proto->IsNull()) return object; 6597 if (proto->IsNull()) return object;
6570 ASSERT(proto->IsJSGlobalObject()); 6598 ASSERT(proto->IsJSGlobalObject());
6571 return SetAccessor(Handle<JSObject>::cast(proto), info); 6599 return SetAccessor(Handle<JSObject>::cast(proto), info);
6572 } 6600 }
6573 6601
6574 // Make sure that the top context does not change when doing callbacks or 6602 // Make sure that the top context does not change when doing callbacks or
6575 // interceptor calls. 6603 // interceptor calls.
6576 AssertNoContextChange ncc(isolate); 6604 AssertNoContextChange ncc(isolate);
6577 6605
6578 // Try to flatten before operating on the string. 6606 // Try to flatten before operating on the string.
6579 if (name->IsString()) FlattenString(Handle<String>::cast(name)); 6607 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
6580 6608
6581 if (!JSObject::CanSetCallback(object, name)) { 6609 if (!JSObject::CanSetCallback(object, name)) {
6582 return factory->undefined_value(); 6610 return factory->undefined_value();
6583 } 6611 }
6584 6612
6585 uint32_t index = 0; 6613 uint32_t index = 0;
6586 bool is_element = name->AsArrayIndex(&index); 6614 bool is_element = name->AsArrayIndex(&index);
6587 6615
6588 if (is_element) { 6616 if (is_element) {
6589 if (object->IsJSArray()) return factory->undefined_value(); 6617 if (object->IsJSArray()) return factory->undefined_value();
(...skipping 10121 matching lines...) Expand 10 before | Expand all | Expand 10 after
16711 #define ERROR_MESSAGES_TEXTS(C, T) T, 16739 #define ERROR_MESSAGES_TEXTS(C, T) T,
16712 static const char* error_messages_[] = { 16740 static const char* error_messages_[] = {
16713 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16741 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16714 }; 16742 };
16715 #undef ERROR_MESSAGES_TEXTS 16743 #undef ERROR_MESSAGES_TEXTS
16716 return error_messages_[reason]; 16744 return error_messages_[reason];
16717 } 16745 }
16718 16746
16719 16747
16720 } } // namespace v8::internal 16748 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698