Reviewers: Søren Gjesse,

Description:
Inline fast case of the method that ensures that an array has a
certain size.

Please review this at http://codereview.chromium.org/126265

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/objects-inl.h
   M     src/objects.h
   M     src/objects.cc


Index: src/objects.cc
===================================================================
--- src/objects.cc      (revision 2199)
+++ src/objects.cc      (working copy)
@@ -4977,10 +4977,8 @@
  }


-void JSArray::EnsureSize(int required_size) {
+void JSArray::Expand(int required_size) {
    Handle<JSArray> self(this);
-  ASSERT(HasFastElements());
-  if (elements()->length() >= required_size) return;
    Handle<FixedArray> old_backing(elements());
    int old_size = old_backing->length();
    // Doubling in size would be overkill, but leave some slack to avoid
Index: src/objects.h
===================================================================
--- src/objects.h       (revision 2199)
+++ src/objects.h       (working copy)
@@ -3982,7 +3982,7 @@

    // Uses handles.  Ensures that the fixed array backing the JSArray has at
    // least the stated size.
-  void EnsureSize(int minimum_size_of_backing_fixed_array);
+  inline void EnsureSize(int minimum_size_of_backing_fixed_array);

    // Dispatched behavior.
  #ifdef DEBUG
@@ -3995,6 +3995,10 @@
    static const int kSize = kLengthOffset + kPointerSize;

   private:
+  // Expand the fixed array backing of a fast-case JSArray to at least
+  // the requested size.
+  void Expand(int minimum_size_of_backing_fixed_array);
+
    DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
  };

Index: src/objects-inl.h
===================================================================
--- src/objects-inl.h   (revision 2199)
+++ src/objects-inl.h   (working copy)
@@ -2639,6 +2639,13 @@
  }


+void JSArray::EnsureSize(int required_size) {
+  ASSERT(HasFastElements());
+  if (elements()->length() >= required_size) return;
+  Expand(required_size);
+}
+
+
  void JSArray::SetContent(FixedArray* storage) {
    set_length(Smi::FromInt(storage->length()), SKIP_WRITE_BARRIER);
    set_elements(storage);



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to