Jacek Caban : jscript: Reuse temporary heap.

Alexandre Julliard julliard at winehq.org
Tue Sep 16 06:54:22 CDT 2008


Module: wine
Branch: master
Commit: 4ac24dc2bf9dc6cf783405968162461867a36aeb
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4ac24dc2bf9dc6cf783405968162461867a36aeb

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Sep 15 20:38:46 2008 +0200

jscript: Reuse temporary heap.

---

 dlls/jscript/engine.h  |    3 +--
 dlls/jscript/jscript.c |    2 ++
 dlls/jscript/jscript.h |   31 ++++++++++++++++++-------------
 dlls/jscript/jsutils.c |   25 +++++++++++++++++++++++++
 dlls/jscript/parser.y  |    5 +++--
 5 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 0d75716..c37bc24 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -35,7 +35,6 @@ typedef struct _parser_ctx_t {
     BOOL nl;
     HRESULT hres;
 
-    jsheap_t tmp_heap;
     jsheap_t heap;
 
     obj_literal_t *obj_literals;
@@ -60,7 +59,7 @@ static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
 
 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
 {
-    return jsheap_alloc(&ctx->tmp_heap, size);
+    return jsheap_alloc(&ctx->script->tmp_heap, size);
 }
 
 typedef struct _scope_chain_t {
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index 899f59d..7c7def0 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -54,6 +54,7 @@ void script_release(script_ctx_t *ctx)
     if(--ctx->ref)
         return;
 
+    jsheap_free(&ctx->tmp_heap);
     heap_free(ctx);
 }
 
@@ -507,6 +508,7 @@ static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
 
     ctx->ref = 1;
     ctx->state = SCRIPTSTATE_UNINITIALIZED;
+    jsheap_init(&ctx->tmp_heap);
 
     ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
     if(ctx) {
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index ec42011..8e6fe3c 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -40,6 +40,22 @@ typedef struct {
     VARIANT var;
 } jsexcept_t;
 
+typedef struct {
+    void **blocks;
+    DWORD block_cnt;
+    DWORD last_block;
+    DWORD offset;
+    BOOL mark;
+    struct list custom_blocks;
+} jsheap_t;
+
+void jsheap_init(jsheap_t*);
+void *jsheap_alloc(jsheap_t*,DWORD);
+void *jsheap_grow(jsheap_t*,void*,DWORD,DWORD);
+void jsheap_clear(jsheap_t*);
+void jsheap_free(jsheap_t*);
+jsheap_t *jsheap_mark(jsheap_t*);
+
 typedef struct DispatchEx DispatchEx;
 
 #define PROPF_ARGMASK 0x00ff
@@ -139,6 +155,8 @@ struct _script_ctx_t {
     named_item_t *named_items;
     LCID lcid;
 
+    jsheap_t tmp_heap;
+
     DispatchEx *script_disp;
     DispatchEx *global;
     DispatchEx *array_constr;
@@ -179,19 +197,6 @@ const char *debugstr_variant(const VARIANT*);
 
 HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
 
-typedef struct {
-    void **blocks;
-    DWORD block_cnt;
-    DWORD last_block;
-    DWORD offset;
-    struct list custom_blocks;
-} jsheap_t;
-
-void jsheap_init(jsheap_t*);
-void *jsheap_alloc(jsheap_t*,DWORD);
-void jsheap_clear(jsheap_t*);
-void jsheap_free(jsheap_t*);
-
 extern LONG module_ref;
 
 static inline void lock_module(void)
diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c
index a193b9e..ae39218 100644
--- a/dlls/jscript/jsutils.c
+++ b/dlls/jscript/jsutils.c
@@ -110,14 +110,30 @@ void *jsheap_alloc(jsheap_t *heap, DWORD size)
     return list+1;
 }
 
+void *jsheap_grow(jsheap_t *heap, void *mem, DWORD size, DWORD inc)
+{
+    if(mem == (BYTE*)heap->blocks[heap->last_block] + heap->offset-size
+       && heap->offset+inc < block_size(heap->last_block)) {
+        heap->offset += inc;
+        return mem;
+    }
+
+    return jsheap_alloc(heap, size+inc);
+}
+
 void jsheap_clear(jsheap_t *heap)
 {
     struct list *tmp;
 
+    if(!heap)
+        return;
+
     while((tmp = list_next(&heap->custom_blocks, &heap->custom_blocks))) {
         list_remove(tmp);
         heap_free(tmp);
     }
+
+    heap->last_block = heap->offset = 0;
 }
 
 void jsheap_free(jsheap_t *heap)
@@ -133,6 +149,15 @@ void jsheap_free(jsheap_t *heap)
     jsheap_init(heap);
 }
 
+jsheap_t *jsheap_mark(jsheap_t *heap)
+{
+    if(heap->mark)
+        return NULL;
+
+    heap->mark = TRUE;
+    return heap;
+}
+
 /* ECMA-262 3rd Edition    9.1 */
 HRESULT to_primitive(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret)
 {
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index ec5f4bd..f721a8e 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -1525,6 +1525,7 @@ void parser_release(parser_ctx_t *ctx)
 HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, parser_ctx_t **ret)
 {
     parser_ctx_t *parser_ctx;
+    jsheap_t *mark;
     HRESULT hres;
 
     parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
@@ -1540,11 +1541,11 @@ HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, parser_ctx_t **ret)
     script_addref(ctx);
     parser_ctx->script = ctx;
 
-    jsheap_init(&parser_ctx->tmp_heap);
+    mark = jsheap_mark(&ctx->tmp_heap);
     jsheap_init(&parser_ctx->heap);
 
     parser_parse(parser_ctx);
-    jsheap_free(&parser_ctx->tmp_heap);
+    jsheap_clear(mark);
     if(FAILED(parser_ctx->hres)) {
         hres = parser_ctx->hres;
         parser_release(parser_ctx);




More information about the wine-cvs mailing list