jscript: Reuse temporary heap.
This commit is contained in:
parent
cf1863ed09
commit
4ac24dc2bf
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue