Introduced copy constructor for List<T, P> and changed constructor of VirtualFrame...
authorbak@chromium.org <bak@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 19 May 2009 13:26:02 +0000 (13:26 +0000)
committerbak@chromium.org <bak@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 19 May 2009 13:26:02 +0000 (13:26 +0000)
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
src/list-inl.h
src/list.h
src/virtual-frame.cc

index f4a074c4e13b696cc9e134710a0eb97eb8811d5f..7af5721f2c03b982b28575bb938402fdcd467ed2 100644 (file)
@@ -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_;
index e3d251fba5ceb91a731a8a014246a472a9538a68..da8bb13d90ab8fd967cc3523a3be4055d9d5c4b9 100644 (file)
 namespace v8 { namespace internal {
 
 
+template<typename T, class P>
+List<T, P>::List(const List<T, P>& 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<typename T, class P>
 void List<T, P>::Add(const T& element) {
   if (length_ < capacity_) {
index 92d23ea391e557192cdabf1254209fd4dbab6e4a..cef0369d187c1024a2ebe76fd989bca63af6e6e4 100644 (file)
@@ -48,6 +48,7 @@ class List {
  public:
 
   INLINE(explicit List(int capacity)) { Initialize(capacity); }
+  INLINE(explicit List(const List<T, P>& 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;
index b9a53a31ce3d1242538db9b5f9c666b1b9431e8c..63f6554dd28ea717a7d8b1bd3456040d6440b7b2 100644 (file)
@@ -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(&register_locations_,
+         original->register_locations_,
+         sizeof(register_locations_));
 }