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

Side by Side Diff: src/builtins.cc

Issue 1559004: Fix the case of no words to copy. (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/utils.h » ('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 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 261 }
262 262
263 263
264 static void CopyElements(AssertNoAllocation* no_gc, 264 static void CopyElements(AssertNoAllocation* no_gc,
265 FixedArray* dst, 265 FixedArray* dst,
266 int dst_index, 266 int dst_index,
267 FixedArray* src, 267 FixedArray* src,
268 int src_index, 268 int src_index,
269 int len) { 269 int len) {
270 ASSERT(dst != src); // Use MoveElements instead. 270 ASSERT(dst != src); // Use MoveElements instead.
271 ASSERT(len > 0);
271 CopyWords(dst->data_start() + dst_index, 272 CopyWords(dst->data_start() + dst_index,
272 src->data_start() + src_index, 273 src->data_start() + src_index,
273 len); 274 len);
274 WriteBarrierMode mode = dst->GetWriteBarrierMode(*no_gc); 275 WriteBarrierMode mode = dst->GetWriteBarrierMode(*no_gc);
275 if (mode == UPDATE_WRITE_BARRIER) { 276 if (mode == UPDATE_WRITE_BARRIER) {
276 Heap::RecordWrites(dst->address(), dst->OffsetOfElementAt(dst_index), len); 277 Heap::RecordWrites(dst->address(), dst->OffsetOfElementAt(dst_index), len);
277 } 278 }
278 } 279 }
279 280
280 281
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 int new_length = len + to_add; 384 int new_length = len + to_add;
384 385
385 if (new_length > elms->length()) { 386 if (new_length > elms->length()) {
386 // New backing storage is needed. 387 // New backing storage is needed.
387 int capacity = new_length + (new_length >> 1) + 16; 388 int capacity = new_length + (new_length >> 1) + 16;
388 Object* obj = Heap::AllocateUninitializedFixedArray(capacity); 389 Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
389 if (obj->IsFailure()) return obj; 390 if (obj->IsFailure()) return obj;
390 FixedArray* new_elms = FixedArray::cast(obj); 391 FixedArray* new_elms = FixedArray::cast(obj);
391 392
392 AssertNoAllocation no_gc; 393 AssertNoAllocation no_gc;
393 CopyElements(&no_gc, new_elms, 0, elms, 0, len); 394 if (len > 0) {
395 CopyElements(&no_gc, new_elms, 0, elms, 0, len);
396 }
394 FillWithHoles(new_elms, new_length, capacity); 397 FillWithHoles(new_elms, new_length, capacity);
395 398
396 elms = new_elms; 399 elms = new_elms;
397 array->set_elements(elms); 400 array->set_elements(elms);
398 } 401 }
399 402
400 // Add the provided values. 403 // Add the provided values.
401 AssertNoAllocation no_gc; 404 AssertNoAllocation no_gc;
402 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); 405 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
403 for (int index = 0; index < to_add; index++) { 406 for (int index = 0; index < to_add; index++) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 ASSERT(to_add <= (Smi::kMaxValue - len)); 533 ASSERT(to_add <= (Smi::kMaxValue - len));
531 534
532 if (new_length > elms->length()) { 535 if (new_length > elms->length()) {
533 // New backing storage is needed. 536 // New backing storage is needed.
534 int capacity = new_length + (new_length >> 1) + 16; 537 int capacity = new_length + (new_length >> 1) + 16;
535 Object* obj = Heap::AllocateUninitializedFixedArray(capacity); 538 Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
536 if (obj->IsFailure()) return obj; 539 if (obj->IsFailure()) return obj;
537 FixedArray* new_elms = FixedArray::cast(obj); 540 FixedArray* new_elms = FixedArray::cast(obj);
538 541
539 AssertNoAllocation no_gc; 542 AssertNoAllocation no_gc;
540 CopyElements(&no_gc, new_elms, to_add, elms, 0, len); 543 if (len > 0) {
544 CopyElements(&no_gc, new_elms, to_add, elms, 0, len);
545 }
541 FillWithHoles(new_elms, new_length, capacity); 546 FillWithHoles(new_elms, new_length, capacity);
542 547
543 elms = new_elms; 548 elms = new_elms;
544 array->set_elements(elms); 549 array->set_elements(elms);
545 } else { 550 } else {
546 AssertNoAllocation no_gc; 551 AssertNoAllocation no_gc;
547 MoveElements(&no_gc, elms, to_add, elms, 0, len); 552 MoveElements(&no_gc, elms, to_add, elms, 0, len);
548 } 553 }
549 554
550 // Add the provided values. 555 // Add the provided values.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 // Check if array need to grow. 732 // Check if array need to grow.
728 if (new_length > elms->length()) { 733 if (new_length > elms->length()) {
729 // New backing storage is needed. 734 // New backing storage is needed.
730 int capacity = new_length + (new_length >> 1) + 16; 735 int capacity = new_length + (new_length >> 1) + 16;
731 Object* obj = Heap::AllocateUninitializedFixedArray(capacity); 736 Object* obj = Heap::AllocateUninitializedFixedArray(capacity);
732 if (obj->IsFailure()) return obj; 737 if (obj->IsFailure()) return obj;
733 FixedArray* new_elms = FixedArray::cast(obj); 738 FixedArray* new_elms = FixedArray::cast(obj);
734 739
735 AssertNoAllocation no_gc; 740 AssertNoAllocation no_gc;
736 // Copy the part before actual_start as is. 741 // Copy the part before actual_start as is.
737 CopyElements(&no_gc, new_elms, 0, elms, 0, actual_start); 742 if (actual_start > 0) {
738 CopyElements(&no_gc, 743 CopyElements(&no_gc, new_elms, 0, elms, 0, actual_start);
739 new_elms, actual_start + item_count, 744 }
740 elms, actual_start + actual_delete_count, 745 const int to_copy = len - actual_delete_count - actual_start;
741 (len - actual_delete_count - actual_start)); 746 if (to_copy > 0) {
747 CopyElements(&no_gc,
748 new_elms, actual_start + item_count,
749 elms, actual_start + actual_delete_count,
750 to_copy);
751 }
742 FillWithHoles(new_elms, new_length, capacity); 752 FillWithHoles(new_elms, new_length, capacity);
743 753
744 elms = new_elms; 754 elms = new_elms;
745 array->set_elements(elms); 755 array->set_elements(elms);
746 } else { 756 } else {
747 AssertNoAllocation no_gc; 757 AssertNoAllocation no_gc;
748 MoveElements(&no_gc, 758 MoveElements(&no_gc,
749 elms, actual_start + item_count, 759 elms, actual_start + item_count,
750 elms, actual_start + actual_delete_count, 760 elms, actual_start + actual_delete_count,
751 (len - actual_delete_count - actual_start)); 761 (len - actual_delete_count - actual_start));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 815
806 result = Heap::AllocateUninitializedFixedArray(result_len); 816 result = Heap::AllocateUninitializedFixedArray(result_len);
807 if (result->IsFailure()) return result; 817 if (result->IsFailure()) return result;
808 FixedArray* result_elms = FixedArray::cast(result); 818 FixedArray* result_elms = FixedArray::cast(result);
809 819
810 // Copy data. 820 // Copy data.
811 AssertNoAllocation no_gc; 821 AssertNoAllocation no_gc;
812 int start_pos = 0; 822 int start_pos = 0;
813 for (int i = 0; i < n_arguments; i++) { 823 for (int i = 0; i < n_arguments; i++) {
814 JSArray* array = JSArray::cast(args[i]); 824 JSArray* array = JSArray::cast(args[i]);
815 FixedArray* elms = FixedArray::cast(array->elements());
816 int len = Smi::cast(array->length())->value(); 825 int len = Smi::cast(array->length())->value();
817 CopyElements(&no_gc, result_elms, start_pos, elms, 0, len); 826 if (len > 0) {
818 start_pos += len; 827 FixedArray* elms = FixedArray::cast(array->elements());
828 CopyElements(&no_gc, result_elms, start_pos, elms, 0, len);
829 start_pos += len;
830 }
819 } 831 }
820 ASSERT(start_pos == result_len); 832 ASSERT(start_pos == result_len);
821 833
822 // Set the length and elements. 834 // Set the length and elements.
823 result_array->set_length(Smi::FromInt(result_len)); 835 result_array->set_length(Smi::FromInt(result_len));
824 result_array->set_elements(result_elms); 836 result_array->set_elements(result_elms);
825 837
826 return result_array; 838 return result_array;
827 } 839 }
828 840
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 if (entry->contains(pc)) { 1482 if (entry->contains(pc)) {
1471 return names_[i]; 1483 return names_[i];
1472 } 1484 }
1473 } 1485 }
1474 } 1486 }
1475 return NULL; 1487 return NULL;
1476 } 1488 }
1477 1489
1478 1490
1479 } } // namespace v8::internal 1491 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698