jscript: Reuse static instance of 'undefined' string.

This commit is contained in:
Jacek Caban 2013-03-08 11:37:56 +01:00 committed by Alexandre Julliard
parent c7c71b87b8
commit d7f24b0956
8 changed files with 33 additions and 80 deletions

View File

@ -1698,13 +1698,11 @@ static HRESULT interp_typeofid(exec_ctx_t *ctx)
DISPID id; DISPID id;
HRESULT hres; HRESULT hres;
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
TRACE("\n"); TRACE("\n");
obj = stack_pop_objid(ctx, &id); obj = stack_pop_objid(ctx, &id);
if(!obj) if(!obj)
return stack_push_string(ctx, undefinedW); return stack_push(ctx, jsval_string(jsstr_undefined()));
hres = disp_propget(ctx->script, obj, id, &v); hres = disp_propget(ctx->script, obj, id, &v);
IDispatch_Release(obj); IDispatch_Release(obj);
@ -1735,7 +1733,7 @@ static HRESULT interp_typeofident(exec_ctx_t *ctx)
return hres; return hres;
if(exprval.type == EXPRVAL_INVALID) { if(exprval.type == EXPRVAL_INVALID) {
hres = stack_push_string(ctx, undefinedW); hres = stack_push(ctx, jsval_string(jsstr_undefined()));
exprval_release(&exprval); exprval_release(&exprval);
return hres; return hres;
} }

View File

@ -286,14 +286,8 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
TRACE("\n"); TRACE("\n");
if(!argc) { if(!argc) {
if(r) { if(r)
ret_str = jsstr_alloc(undefinedW); *r = jsval_string(jsstr_undefined());
if(!ret_str)
return E_OUTOFMEMORY;
*r = jsval_string(ret_str);
}
return S_OK; return S_OK;
} }
@ -640,13 +634,8 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
TRACE("\n"); TRACE("\n");
if(!argc) { if(!argc) {
if(r) { if(r)
ret_str = jsstr_alloc(undefinedW); *r = jsval_string(jsstr_undefined());
if(!ret_str)
return E_OUTOFMEMORY;
*r = jsval_string(ret_str);
}
return S_OK; return S_OK;
} }
@ -781,14 +770,8 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
TRACE("\n"); TRACE("\n");
if(!argc) { if(!argc) {
if(r) { if(r)
ret = jsstr_alloc(undefinedW); *r = jsval_string(jsstr_undefined());
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK; return S_OK;
} }
@ -853,14 +836,8 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
TRACE("\n"); TRACE("\n");
if(!argc) { if(!argc) {
if(r) { if(r)
ret = jsstr_alloc(undefinedW); *r = jsval_string(jsstr_undefined());
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK; return S_OK;
} }
@ -944,14 +921,8 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
TRACE("\n"); TRACE("\n");
if(!argc) { if(!argc) {
if(r) { if(r)
ret = jsstr_alloc(undefinedW); *r = jsval_string(jsstr_undefined());
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK; return S_OK;
} }
@ -1014,14 +985,8 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
TRACE("\n"); TRACE("\n");
if(!argc) { if(!argc) {
if(r) { if(r)
ret = jsstr_alloc(undefinedW); *r = jsval_string(jsstr_undefined());
if(!ret)
return E_OUTOFMEMORY;
*r = jsval_string(ret);
}
return S_OK; return S_OK;
} }

View File

@ -58,7 +58,6 @@ static const WCHAR idx7W[] = {'$','7',0};
static const WCHAR idx8W[] = {'$','8',0}; static const WCHAR idx8W[] = {'$','8',0};
static const WCHAR idx9W[] = {'$','9',0}; static const WCHAR idx9W[] = {'$','9',0};
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
static const WCHAR emptyW[] = {0}; static const WCHAR emptyW[] = {0};
static inline RegExpInstance *regexp_from_vdisp(vdisp_t *vdisp) static inline RegExpInstance *regexp_from_vdisp(vdisp_t *vdisp)
@ -487,21 +486,15 @@ static HRESULT RegExp_test(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsig
jsval_t *r) jsval_t *r)
{ {
match_state_t *match; match_state_t *match;
heap_pool_t *mark;
jsstr_t *undef_str; jsstr_t *undef_str;
heap_pool_t *mark;
BOOL b; BOOL b;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
if(!argc) {
undef_str = jsstr_alloc(undefinedW);
if(!undef_str)
return E_OUTOFMEMORY;
}
mark = heap_pool_mark(&ctx->tmp_heap); mark = heap_pool_mark(&ctx->tmp_heap);
hres = run_exec(ctx, jsthis, argc ? argv[0] : jsval_string(undef_str), NULL, &match, &b); hres = run_exec(ctx, jsthis, argc ? argv[0] : jsval_string(undef_str = jsstr_undefined()), NULL, &match, &b);
heap_pool_clear(mark); heap_pool_clear(mark);
if(!argc) if(!argc)
jsstr_release(undef_str); jsstr_release(undef_str);

View File

@ -88,7 +88,7 @@ jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2)
return ret; return ret;
} }
static jsstr_t *empty_str, *nan_str; static jsstr_t *empty_str, *nan_str, *undefined_str;
jsstr_t *jsstr_nan(void) jsstr_t *jsstr_nan(void)
{ {
@ -100,14 +100,22 @@ jsstr_t *jsstr_empty(void)
return jsstr_addref(empty_str); return jsstr_addref(empty_str);
} }
jsstr_t *jsstr_undefined(void)
{
return jsstr_addref(undefined_str);
}
BOOL init_strings(void) BOOL init_strings(void)
{ {
static const WCHAR NaNW[] = { 'N','a','N',0 }; static const WCHAR NaNW[] = { 'N','a','N',0 };
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
if(!(empty_str = jsstr_alloc_buf(0))) if(!(empty_str = jsstr_alloc_buf(0)))
return FALSE; return FALSE;
if(!(nan_str = jsstr_alloc(NaNW))) if(!(nan_str = jsstr_alloc(NaNW)))
return FALSE; return FALSE;
if(!(undefined_str = jsstr_alloc(undefinedW)))
return FALSE;
return TRUE; return TRUE;
} }
@ -115,4 +123,5 @@ void free_strings(void)
{ {
jsstr_release(empty_str); jsstr_release(empty_str);
jsstr_release(nan_str); jsstr_release(nan_str);
jsstr_release(undefined_str);
} }

View File

@ -76,6 +76,7 @@ jsstr_t *jsstr_concat(jsstr_t*,jsstr_t*) DECLSPEC_HIDDEN;
jsstr_t *jsstr_nan(void) DECLSPEC_HIDDEN; jsstr_t *jsstr_nan(void) DECLSPEC_HIDDEN;
jsstr_t *jsstr_empty(void) DECLSPEC_HIDDEN; jsstr_t *jsstr_empty(void) DECLSPEC_HIDDEN;
jsstr_t *jsstr_undefined(void) DECLSPEC_HIDDEN;
BOOL init_strings(void) DECLSPEC_HIDDEN; BOOL init_strings(void) DECLSPEC_HIDDEN;
void free_strings(void) DECLSPEC_HIDDEN; void free_strings(void) DECLSPEC_HIDDEN;

View File

@ -738,15 +738,14 @@ HRESULT double_to_string(double n, jsstr_t **str)
/* ECMA-262 3rd Edition 9.8 */ /* ECMA-262 3rd Edition 9.8 */
HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str) HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str)
{ {
const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
const WCHAR nullW[] = {'n','u','l','l',0}; const WCHAR nullW[] = {'n','u','l','l',0};
const WCHAR trueW[] = {'t','r','u','e',0}; const WCHAR trueW[] = {'t','r','u','e',0};
const WCHAR falseW[] = {'f','a','l','s','e',0}; const WCHAR falseW[] = {'f','a','l','s','e',0};
switch(jsval_type(val)) { switch(jsval_type(val)) {
case JSV_UNDEFINED: case JSV_UNDEFINED:
*str = jsstr_alloc(undefinedW); *str = jsstr_undefined();
break; return S_OK;
case JSV_NULL: case JSV_NULL:
*str = jsstr_alloc(nullW); *str = jsstr_alloc(nullW);
break; break;

View File

@ -59,7 +59,6 @@ static const WCHAR throwW[] = {'t','h','r','o','w',0};
static const WCHAR trueW[] = {'t','r','u','e',0}; static const WCHAR trueW[] = {'t','r','u','e',0};
static const WCHAR tryW[] = {'t','r','y',0}; static const WCHAR tryW[] = {'t','r','y',0};
static const WCHAR typeofW[] = {'t','y','p','e','o','f',0}; static const WCHAR typeofW[] = {'t','y','p','e','o','f',0};
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
static const WCHAR varW[] = {'v','a','r',0}; static const WCHAR varW[] = {'v','a','r',0};
static const WCHAR voidW[] = {'v','o','i','d',0}; static const WCHAR voidW[] = {'v','o','i','d',0};
static const WCHAR whileW[] = {'w','h','i','l','e',0}; static const WCHAR whileW[] = {'w','h','i','l','e',0};

View File

@ -188,10 +188,7 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, j
static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsigned argc, jsval_t *argv, jsval_t *r, static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsigned argc, jsval_t *argv, jsval_t *r,
const WCHAR *tagname, const WCHAR *attrname) const WCHAR *tagname, const WCHAR *attrname)
{ {
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
jsstr_t *str, *attr_value = NULL; jsstr_t *str, *attr_value = NULL;
unsigned attr_len;
HRESULT hres; HRESULT hres;
hres = get_string_val(ctx, jsthis, &str); hres = get_string_val(ctx, jsthis, &str);
@ -204,9 +201,8 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
jsstr_release(str); jsstr_release(str);
return hres; return hres;
} }
attr_len = jsstr_length(attr_value);
}else { }else {
attr_len = sizeof(undefinedW)/sizeof(WCHAR)-1; attr_value = jsstr_undefined();
} }
if(r) { if(r) {
@ -214,7 +210,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
unsigned tagname_len = strlenW(tagname); unsigned tagname_len = strlenW(tagname);
jsstr_t *ret; jsstr_t *ret;
ret = jsstr_alloc_buf(2*tagname_len + attrname_len + attr_len + jsstr_length(str) + 9); ret = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9);
if(ret) { if(ret) {
WCHAR *ptr = ret->str; WCHAR *ptr = ret->str;
@ -226,13 +222,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
ptr += attrname_len; ptr += attrname_len;
*ptr++ = '='; *ptr++ = '=';
*ptr++ = '"'; *ptr++ = '"';
ptr += jsstr_flush(attr_value, ptr);
if(attr_value)
jsstr_flush(attr_value, ptr);
else
memcpy(ptr, undefinedW, attr_len*sizeof(WCHAR));
ptr += attr_len;
*ptr++ = '"'; *ptr++ = '"';
*ptr++ = '>'; *ptr++ = '>';
ptr += jsstr_flush(str, ptr); ptr += jsstr_flush(str, ptr);
@ -249,8 +239,7 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
} }
} }
if(attr_value) jsstr_release(attr_value);
jsstr_release(attr_value);
jsstr_release(str); jsstr_release(str);
return hres; return hres;
} }