Bug 841619 - Factor out an ArrayBufferObject::changeContents from uninlineData (r=sfink)
authorLuke Wagner <luke@mozilla.com>
Thu, 14 Feb 2013 15:08:15 -0800
changeset 131964 533b1bc8ca2147ba652f1437978894e22014f39a
parent 131963 f1f4c2e87acf2a5bb05d9d10fb8faec84c83205f
child 131965 fb6dd685d3a91b953c17e2dca3a6b44d7a381c95
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs841619
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 841619 - Factor out an ArrayBufferObject::changeContents from uninlineData (r=sfink)
js/src/jstypedarray.cpp
js/src/jstypedarray.h
--- a/js/src/jstypedarray.cpp
+++ b/js/src/jstypedarray.cpp
@@ -268,46 +268,50 @@ GetViewList(ArrayBufferObject *obj)
             uint32_t capacity;
             uint32_t initializedLength;
             JSObject *views;
     };
     return &reinterpret_cast<OldObjectRepresentationHack*>(obj->getElementsHeader())->views;
 #endif
 }
 
+void
+ArrayBufferObject::changeContents(ObjectElements *newHeader)
+{
+   // Grab out data before invalidating it.
+   uint32_t byteLengthCopy = byteLength();
+   uintptr_t oldDataPointer = uintptr_t(dataPointer());
+   JSObject *viewListHead = *GetViewList(this);
+
+   // Update all views.
+   uintptr_t newDataPointer = uintptr_t(newHeader->elements());
+   for (JSObject *view = viewListHead; view; view = NextView(view)) {
+       uintptr_t newDataPtr = uintptr_t(view->getPrivate()) - oldDataPointer + newDataPointer;
+       view->setPrivate(reinterpret_cast<uint8_t*>(newDataPtr));
+   }
+
+   // Change to the new header (now, so we can use GetViewList).
+   elements = newHeader->elements();
+
+   // Initialize 'newHeader'.
+   ArrayBufferObject::setElementsHeader(newHeader, byteLengthCopy);
+   *GetViewList(this) = viewListHead;
+}
+
 bool
 ArrayBufferObject::uninlineData(JSContext *maybecx)
 {
    if (hasDynamicElements())
        return true;
 
-   // Grab out data before invalidating it
-   uint32_t bytes = byteLength();
-   uintptr_t oldPointer = uintptr_t(dataPointer());
-   JSObject *view = *GetViewList(this);
-   JSObject *viewListHead = view;
-
-   ObjectElements *header = AllocateArrayBufferContents(maybecx, bytes,
-                                                        reinterpret_cast<uint8_t*>(oldPointer));
-   if (!header)
+   ObjectElements *newHeader = AllocateArrayBufferContents(maybecx, byteLength(), dataPointer());
+   if (!newHeader)
        return false;
-   elements = header->elements();
-   setElementsHeader(getElementsHeader(), bytes);
-
-   // Update all views
-   uintptr_t newPointer = uintptr_t(dataPointer());
-   while (view) {
-       uintptr_t newDataPtr = uintptr_t(view->getPrivate()) - oldPointer + newPointer;
-       view->setPrivate(reinterpret_cast<uint8_t*>(newDataPtr));
-       view = NextView(view);
-   }
-
-   // Restore the list of views
-   *GetViewList(this) = viewListHead;
-
+
+   changeContents(newHeader);
    return true;
 }
 
 #ifdef JSGC_GENERATIONAL
 class WeakObjectSlotRef : public js::gc::BufferableRef
 {
     JSObject *owner;
     size_t slot;
--- a/js/src/jstypedarray.h
+++ b/js/src/jstypedarray.h
@@ -141,16 +141,17 @@ class ArrayBufferObject : public JSObjec
     static bool stealContents(JSContext *cx, JSObject *obj, void **contents,
                               uint8_t **data);
 
     static inline void setElementsHeader(js::ObjectElements *header, uint32_t bytes);
 
     void addView(RawObject view);
 
     bool allocateSlots(JSContext *cx, uint32_t size, uint8_t *contents = NULL);
+    void changeContents(ObjectElements *newHeader);
 
     /*
      * Ensure that the data is not stored inline. Used when handing back a
      * GC-safe pointer.
      */
     bool uninlineData(JSContext *cx);
 
     inline uint32_t byteLength() const;