Bug 1248534 (part 6) - Stack-allocate XPTState. r=khuey.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 23 Feb 2016 05:33:35 +1100
changeset 321859 76740f3273fb519efe26f1dd345be20f5c9668d0
parent 321858 25c818450f3229d4b3904f5eb8a27c4a4d6fb27c
child 321860 fa81f18d5093d47064913e1e7fb6c54d03419df0
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1248534
milestone47.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 1248534 (part 6) - Stack-allocate XPTState. r=khuey. RegisterBuffer() is the only place that creates an XPTState, and it also destroys it. So the XPTState can be allocated on the stack, which voids the need for the creation of an XPTArena.
xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
xpcom/typelib/xpt/xpt_xdr.cpp
xpcom/typelib/xpt/xpt_xdr.h
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
@@ -94,32 +94,28 @@ void
 XPTInterfaceInfoManager::InitMemoryReporter()
 {
     RegisterWeakMemoryReporter(this);
 }
 
 void
 XPTInterfaceInfoManager::RegisterBuffer(char *buf, uint32_t length)
 {
-    XPTState *state = XPT_NewXDRState(buf, length);
-    if (!state)
-        return;
+    XPTState state;
+    XPT_InitXDRState(&state, buf, length);
 
     XPTCursor cursor;
-    if (!XPT_MakeCursor(state, XPT_HEADER, 0, &cursor)) {
-        XPT_DestroyXDRState(state);
+    if (!XPT_MakeCursor(&state, XPT_HEADER, 0, &cursor)) {
         return;
     }
 
     XPTHeader *header = nullptr;
     if (XPT_DoHeader(gXPTIStructArena, &cursor, &header)) {
         RegisterXPTHeader(header);
     }
-
-    XPT_DestroyXDRState(state);
 }
 
 void
 XPTInterfaceInfoManager::RegisterXPTHeader(XPTHeader* aHeader)
 {
     if (aHeader->major_version >= XPT_MAJOR_INCOMPATIBLE_VERSION) {
         NS_ASSERTION(!aHeader->num_interfaces,"bad libxpt");
         LOG_AUTOREG(("      file is version %d.%d  Type file of version %d.0 or higher can not be read.\n", (int)header->major_version, (int)header->minor_version, (int)XPT_MAJOR_INCOMPATIBLE_VERSION));
--- a/xpcom/typelib/xpt/xpt_xdr.cpp
+++ b/xpcom/typelib/xpt/xpt_xdr.cpp
@@ -33,51 +33,22 @@ CHECK_COUNT(XPTCursor* cursor, uint32_t 
         XPT_ASSERT(0);
         fprintf(stderr, "FATAL: no room for %d in cursor\n", space);
         return PR_FALSE;
     }
 
     return PR_TRUE;
 }
 
-XPT_PUBLIC_API(XPTState *)
-XPT_NewXDRState(char *data, uint32_t len)
+XPT_PUBLIC_API(void)
+XPT_InitXDRState(XPTState* state, char *data, uint32_t len)
 {
-    XPTState *state;
-    XPTArena *arena;
-
-    arena = XPT_NewArena(512, sizeof(double), "an XDRState");
-    if (!arena)
-        return NULL;
-
-    state = XPT_NEWZAP(arena, XPTState);
-    if (!state)
-        goto err_free_arena;
-
-    state->arena = arena;
     state->next_cursor[0] = state->next_cursor[1] = 1;
     state->pool_data = data;
     state->pool_allocated = len;
-
-    return state;
-
- err_free_arena:
-    if (arena)
-        XPT_DestroyArena(arena);
-    return NULL;
-}
-
-XPT_PUBLIC_API(void)
-XPT_DestroyXDRState(XPTState *state)
-{
-    XPTArena *arena = state->arena;
-
-    XPT_DELETE(arena, state);
-    if (arena)
-        XPT_DestroyArena(arena);
 }
 
 /* All offsets are 1-based */
 XPT_PUBLIC_API(void)
 XPT_SetDataOffset(XPTState *state, uint32_t data_offset)
 {
    state->data_offset = data_offset;
 }
--- a/xpcom/typelib/xpt/xpt_xdr.h
+++ b/xpcom/typelib/xpt/xpt_xdr.h
@@ -45,41 +45,37 @@ XPT_DoHeader(XPTArena *arena, XPTCursor 
 typedef enum {
     XPT_HEADER = 0,
     XPT_DATA = 1
 } XPTPool;
 
 struct XPTState {
     uint32_t         data_offset;
     uint32_t         next_cursor[2];
-    XPTArena         *arena;
     char             *pool_data;
     uint32_t         pool_allocated;
 };
 
 struct XPTCursor {
     XPTState    *state;
     XPTPool     pool;
     uint32_t    offset;
     uint8_t     bits;
 };
 
-extern XPT_PUBLIC_API(XPTState *)
-XPT_NewXDRState(char *data, uint32_t len);
+extern XPT_PUBLIC_API(void)
+XPT_InitXDRState(XPTState* state, char* data, uint32_t len);
 
 extern XPT_PUBLIC_API(PRBool)
 XPT_MakeCursor(XPTState *state, XPTPool pool, uint32_t len, XPTCursor *cursor);
 
 extern XPT_PUBLIC_API(PRBool)
 XPT_SeekTo(XPTCursor *cursor, uint32_t offset);
 
 extern XPT_PUBLIC_API(void)
-XPT_DestroyXDRState(XPTState *state);
-
-extern XPT_PUBLIC_API(void)
 XPT_SetDataOffset(XPTState *state, uint32_t data_offset);
 
 /* all data structures are big-endian */
 
 #if defined IS_BIG_ENDIAN
 #  define XPT_SWAB32(x) x
 #  define XPT_SWAB16(x) x
 #elif defined IS_LITTLE_ENDIAN