From 34865c062b64f4f6d01cfd2b8845f3b754dca124 Mon Sep 17 00:00:00 2001 From: "bak@chromium.org" Date: Tue, 19 May 2009 13:26:02 +0000 Subject: [PATCH] Introduced copy constructor for List and changed constructor of VirtualFrame to use it. Review URL: http://codereview.chromium.org/113582 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2000 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/jump-target.cc | 9 ++------- src/list-inl.h | 20 ++++++++++++++++++++ src/list.h | 3 +-- src/virtual-frame.cc | 13 +++++-------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/jump-target.cc b/src/jump-target.cc index f4a074c4e1..7af5721f2c 100644 --- a/src/jump-target.cc +++ b/src/jump-target.cc @@ -484,13 +484,8 @@ void BreakTarget::set_direction(Directionality direction) { void BreakTarget::CopyTo(BreakTarget* destination) { ASSERT(destination != NULL); destination->direction_ = direction_; - destination->reaching_frames_.Clear(); - destination->merge_labels_.Clear(); - ASSERT(reaching_frames_.length() == merge_labels_.length()); - for (int i = 0; i < reaching_frames_.length(); i++) { - destination->reaching_frames_.Add(reaching_frames_[i]); - destination->merge_labels_.Add(merge_labels_[i]); - } + destination->reaching_frames_ = reaching_frames_; + destination->merge_labels_ = merge_labels_; destination->entry_frame_ = entry_frame_; destination->entry_label_ = entry_label_; destination->expected_height_ = expected_height_; diff --git a/src/list-inl.h b/src/list-inl.h index e3d251fba5..da8bb13d90 100644 --- a/src/list-inl.h +++ b/src/list-inl.h @@ -33,6 +33,26 @@ namespace v8 { namespace internal { +template +List::List(const List& other) { + ASSERT(other.capacity() >= 0); + capacity_ = other.capacity(); + length_ = other.length(); + if (capacity_ > 0) { + data_ = NewData(capacity_); + int copy_size = length_ * sizeof(T); + const int kMinMemCpySize = 64; + if (copy_size < kMinMemCpySize) { + for (int i = 0; i < length_; i++) data_[i] = other.data_[i]; + } else { + memcpy(data_, other.data_, copy_size); + } + } else { + data_ = NULL; + } +} + + template void List::Add(const T& element) { if (length_ < capacity_) { diff --git a/src/list.h b/src/list.h index 92d23ea391..cef0369d18 100644 --- a/src/list.h +++ b/src/list.h @@ -48,6 +48,7 @@ class List { public: INLINE(explicit List(int capacity)) { Initialize(capacity); } + INLINE(explicit List(const List& other)); INLINE(~List()) { DeleteData(data_); } INLINE(void* operator new(size_t size)) { return P::New(size); } @@ -125,8 +126,6 @@ class List { // Inlined implementation of ResizeAdd, shared by inlined and // non-inlined versions of ResizeAdd. void ResizeAddInternal(const T& element); - - DISALLOW_COPY_AND_ASSIGN(List); }; class FrameElement; diff --git a/src/virtual-frame.cc b/src/virtual-frame.cc index b9a53a31ce..63f6554dd2 100644 --- a/src/virtual-frame.cc +++ b/src/virtual-frame.cc @@ -39,18 +39,15 @@ namespace v8 { namespace internal { VirtualFrame::VirtualFrame(VirtualFrame* original) : cgen_(original->cgen_), masm_(original->masm_), - elements_(original->elements_.capacity()), + elements_(original->elements_), parameter_count_(original->parameter_count_), local_count_(original->local_count_), stack_pointer_(original->stack_pointer_), frame_pointer_(original->frame_pointer_) { - // Copy all the elements from the original. - for (int i = 0; i < original->elements_.length(); i++) { - elements_.Add(original->elements_[i]); - } - for (int i = 0; i < kNumRegisters; i++) { - register_locations_[i] = original->register_locations_[i]; - } + // Copy register locations from original. + memcpy(®ister_locations_, + original->register_locations_, + sizeof(register_locations_)); }