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

Side by Side Diff: src/builtins.cc

Issue 669060: Add runtime function for string to array conversion. (Closed)
Patch Set: Created 10 years, 9 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
« no previous file with comments | « no previous file | src/factory.h » ('j') | src/factory.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 // Set length and elements on the array. 237 // Set length and elements on the array.
238 array->set_elements(FixedArray::cast(obj)); 238 array->set_elements(FixedArray::cast(obj));
239 array->set_length(len); 239 array->set_length(len);
240 240
241 return array; 241 return array;
242 } 242 }
243 243
244 244
245 static Object* AllocateUninitializedFixedArray(int len) {
246 Object* obj = Heap::AllocateRawFixedArray(len);
247 if (obj->IsFailure()) return obj;
248
249 reinterpret_cast<FixedArray*>(obj)->set_map(Heap::fixed_array_map());
250 FixedArray::cast(obj)->set_length(len);
251 return obj;
252 }
253
254
255 static Object* AllocateJSArray() { 245 static Object* AllocateJSArray() {
256 JSFunction* array_function = 246 JSFunction* array_function =
257 Top::context()->global_context()->array_function(); 247 Top::context()->global_context()->array_function();
258 Object* result = Heap::AllocateJSObject(array_function); 248 Object* result = Heap::AllocateJSObject(array_function);
259 if (result->IsFailure()) return result; 249 if (result->IsFailure()) return result;
260 return result; 250 return result;
261 } 251 }
262 252
263 253
264 static void CopyElements(AssertNoAllocation* no_gc, 254 static void CopyElements(AssertNoAllocation* no_gc,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 // Currently fixed arrays cannot grow too big, so 346 // Currently fixed arrays cannot grow too big, so
357 // we should never hit this case. 347 // we should never hit this case.
358 ASSERT(to_add <= (Smi::kMaxValue - len)); 348 ASSERT(to_add <= (Smi::kMaxValue - len));
359 349
360 int new_length = len + to_add; 350 int new_length = len + to_add;
361 FixedArray* elms = FixedArray::cast(array->elements()); 351 FixedArray* elms = FixedArray::cast(array->elements());
362 352
363 if (new_length > elms->length()) { 353 if (new_length > elms->length()) {
364 // New backing storage is needed. 354 // New backing storage is needed.
365 int capacity = new_length + (new_length >> 1) + 16; 355 int capacity = new_length + (new_length >> 1) + 16;
366 Object* obj = AllocateUninitializedFixedArray(capacity); 356 Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
367 if (obj->IsFailure()) return obj; 357 if (obj->IsFailure()) return obj;
368 FixedArray* new_elms = FixedArray::cast(obj); 358 FixedArray* new_elms = FixedArray::cast(obj);
369 359
370 AssertNoAllocation no_gc; 360 AssertNoAllocation no_gc;
371 CopyElements(&no_gc, new_elms, 0, elms, 0, len); 361 CopyElements(&no_gc, new_elms, 0, elms, 0, len);
372 FillWithHoles(new_elms, new_length, capacity); 362 FillWithHoles(new_elms, new_length, capacity);
373 363
374 elms = new_elms; 364 elms = new_elms;
375 array->set_elements(elms); 365 array->set_elements(elms);
376 } 366 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 int new_length = len + to_add; 456 int new_length = len + to_add;
467 // Currently fixed arrays cannot grow too big, so 457 // Currently fixed arrays cannot grow too big, so
468 // we should never hit this case. 458 // we should never hit this case.
469 ASSERT(to_add <= (Smi::kMaxValue - len)); 459 ASSERT(to_add <= (Smi::kMaxValue - len));
470 460
471 FixedArray* elms = FixedArray::cast(array->elements()); 461 FixedArray* elms = FixedArray::cast(array->elements());
472 462
473 if (new_length > elms->length()) { 463 if (new_length > elms->length()) {
474 // New backing storage is needed. 464 // New backing storage is needed.
475 int capacity = new_length + (new_length >> 1) + 16; 465 int capacity = new_length + (new_length >> 1) + 16;
476 Object* obj = AllocateUninitializedFixedArray(capacity); 466 Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
477 if (obj->IsFailure()) return obj; 467 if (obj->IsFailure()) return obj;
478 FixedArray* new_elms = FixedArray::cast(obj); 468 FixedArray* new_elms = FixedArray::cast(obj);
479 469
480 AssertNoAllocation no_gc; 470 AssertNoAllocation no_gc;
481 CopyElements(&no_gc, new_elms, to_add, elms, 0, len); 471 CopyElements(&no_gc, new_elms, to_add, elms, 0, len);
482 FillWithHoles(new_elms, new_length, capacity); 472 FillWithHoles(new_elms, new_length, capacity);
483 473
484 elms = new_elms; 474 elms = new_elms;
485 array->set_elements(elms); 475 array->set_elements(elms);
486 } else { 476 } else {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 // Calculate the length of result array. 536 // Calculate the length of result array.
547 int result_len = final - k; 537 int result_len = final - k;
548 if (result_len < 0) { 538 if (result_len < 0) {
549 result_len = 0; 539 result_len = 0;
550 } 540 }
551 541
552 Object* result = AllocateJSArray(); 542 Object* result = AllocateJSArray();
553 if (result->IsFailure()) return result; 543 if (result->IsFailure()) return result;
554 JSArray* result_array = JSArray::cast(result); 544 JSArray* result_array = JSArray::cast(result);
555 545
556 result = AllocateUninitializedFixedArray(result_len); 546 result = Heap::AllocateUninitializedFixedArray(result_len);
557 if (result->IsFailure()) return result; 547 if (result->IsFailure()) return result;
558 FixedArray* result_elms = FixedArray::cast(result); 548 FixedArray* result_elms = FixedArray::cast(result);
559 549
560 FixedArray* elms = FixedArray::cast(array->elements()); 550 FixedArray* elms = FixedArray::cast(array->elements());
561 551
562 AssertNoAllocation no_gc; 552 AssertNoAllocation no_gc;
563 CopyElements(&no_gc, result_elms, 0, elms, k, result_len); 553 CopyElements(&no_gc, result_elms, 0, elms, k, result_len);
564 554
565 // Set elements. 555 // Set elements.
566 result_array->set_elements(result_elms); 556 result_array->set_elements(result_elms);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 return CallJsBuiltin("ArraySplice", args); 605 return CallJsBuiltin("ArraySplice", args);
616 } 606 }
617 } 607 }
618 int actualDeleteCount = Min(Max(deleteCount, 0), len - actualStart); 608 int actualDeleteCount = Min(Max(deleteCount, 0), len - actualStart);
619 609
620 // Allocate result array. 610 // Allocate result array.
621 Object* result = AllocateJSArray(); 611 Object* result = AllocateJSArray();
622 if (result->IsFailure()) return result; 612 if (result->IsFailure()) return result;
623 JSArray* result_array = JSArray::cast(result); 613 JSArray* result_array = JSArray::cast(result);
624 614
625 result = AllocateUninitializedFixedArray(actualDeleteCount); 615 result = Heap::AllocateUninitializedFixedArray(actualDeleteCount);
626 if (result->IsFailure()) return result; 616 if (result->IsFailure()) return result;
627 FixedArray* result_elms = FixedArray::cast(result); 617 FixedArray* result_elms = FixedArray::cast(result);
628 618
629 FixedArray* elms = FixedArray::cast(array->elements()); 619 FixedArray* elms = FixedArray::cast(array->elements());
630 620
631 AssertNoAllocation no_gc; 621 AssertNoAllocation no_gc;
632 // Fill newly created array. 622 // Fill newly created array.
633 CopyElements(&no_gc, result_elms, 0, elms, actualStart, actualDeleteCount); 623 CopyElements(&no_gc, result_elms, 0, elms, actualStart, actualDeleteCount);
634 624
635 // Set elements. 625 // Set elements.
(...skipping 17 matching lines...) Expand all
653 // Currently fixed arrays cannot grow too big, so 643 // Currently fixed arrays cannot grow too big, so
654 // we should never hit this case. 644 // we should never hit this case.
655 ASSERT((itemCount - actualDeleteCount) <= (Smi::kMaxValue - len)); 645 ASSERT((itemCount - actualDeleteCount) <= (Smi::kMaxValue - len));
656 646
657 FixedArray* source_elms = elms; 647 FixedArray* source_elms = elms;
658 648
659 // Check if array need to grow. 649 // Check if array need to grow.
660 if (new_length > elms->length()) { 650 if (new_length > elms->length()) {
661 // New backing storage is needed. 651 // New backing storage is needed.
662 int capacity = new_length + (new_length >> 1) + 16; 652 int capacity = new_length + (new_length >> 1) + 16;
663 Object* obj = AllocateUninitializedFixedArray(capacity); 653 Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
664 if (obj->IsFailure()) return obj; 654 if (obj->IsFailure()) return obj;
665 FixedArray* new_elms = FixedArray::cast(obj); 655 FixedArray* new_elms = FixedArray::cast(obj);
666 656
667 // Copy the part before actualStart as is. 657 // Copy the part before actualStart as is.
668 CopyElements(&no_gc, new_elms, 0, elms, 0, actualStart); 658 CopyElements(&no_gc, new_elms, 0, elms, 0, actualStart);
669 FillWithHoles(new_elms, new_length, capacity); 659 FillWithHoles(new_elms, new_length, capacity);
670 660
671 source_elms = elms; 661 source_elms = elms;
672 elms = new_elms; 662 elms = new_elms;
673 array->set_elements(elms); 663 array->set_elements(elms);
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 if (entry->contains(pc)) { 1325 if (entry->contains(pc)) {
1336 return names_[i]; 1326 return names_[i];
1337 } 1327 }
1338 } 1328 }
1339 } 1329 }
1340 return NULL; 1330 return NULL;
1341 } 1331 }
1342 1332
1343 1333
1344 } } // namespace v8::internal 1334 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/factory.h » ('j') | src/factory.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698