From 2ac35ac44161dad1fce63006452bbe35be74af91 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 24 Apr 2013 11:32:33 +0200 Subject: [PATCH] jscript: Use single string instance for strings representing NULL BSTR instead of a flag. --- dlls/jscript/jsstr.c | 27 ++++++++++++++++++++++----- dlls/jscript/jsstr.h | 7 ++++--- dlls/jscript/jsutils.c | 16 +++++++++------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/dlls/jscript/jsstr.c b/dlls/jscript/jsstr.c index 0d0eb0fef67..add0195ce8d 100644 --- a/dlls/jscript/jsstr.c +++ b/dlls/jscript/jsstr.c @@ -277,7 +277,7 @@ const WCHAR *jsstr_rope_flatten(jsstr_rope_t *str) return jsstr_as_heap(&str->str)->buf = buf; } -static jsstr_t *empty_str, *nan_str, *undefined_str; +static jsstr_t *empty_str, *nan_str, *undefined_str, *null_bstr_str; jsstr_t *jsstr_nan(void) { @@ -294,6 +294,16 @@ jsstr_t *jsstr_undefined(void) return jsstr_addref(undefined_str); } +jsstr_t *jsstr_null_bstr(void) +{ + return jsstr_addref(null_bstr_str); +} + +BOOL is_null_bstr(jsstr_t *str) +{ + return str == null_bstr_str; +} + BOOL init_strings(void) { static const WCHAR NaNW[] = { 'N','a','N',0 }; @@ -305,12 +315,19 @@ BOOL init_strings(void) return FALSE; if(!(undefined_str = jsstr_alloc(undefinedW))) return FALSE; - return TRUE; + if(!jsstr_alloc_buf(0, &null_bstr_str)) + return FALSE; + return TRUE; } void free_strings(void) { - jsstr_release(empty_str); - jsstr_release(nan_str); - jsstr_release(undefined_str); + if(empty_str) + jsstr_release(empty_str); + if(nan_str) + jsstr_release(nan_str); + if(undefined_str) + jsstr_release(undefined_str); + if(null_bstr_str) + jsstr_release(null_bstr_str); } diff --git a/dlls/jscript/jsstr.h b/dlls/jscript/jsstr.h index 727b2d007a7..2ad03f18959 100644 --- a/dlls/jscript/jsstr.h +++ b/dlls/jscript/jsstr.h @@ -17,7 +17,7 @@ */ /* - * This is a common header for all string representations. The exact layout of the string + * jsstr_t is a common header for all string representations. The exact layout of the string * representation may be: * * - inline string - string bytes directly follow string headers. @@ -42,8 +42,6 @@ struct _jsstr_t { #define JSSTR_MAX_LENGTH (1 << (32-JSSTR_LENGTH_SHIFT)) #define JSSTR_FLAGS_MASK ((1 << JSSTR_LENGTH_SHIFT)-1) -#define JSSTR_FLAG_NULLBSTR 4 - #define JSSTR_FLAG_LBIT 1 #define JSSTR_FLAG_FLAT 2 #define JSSTR_FLAG_TAG_MASK 3 @@ -187,6 +185,9 @@ jsstr_t *jsstr_nan(void) DECLSPEC_HIDDEN; jsstr_t *jsstr_empty(void) DECLSPEC_HIDDEN; jsstr_t *jsstr_undefined(void) DECLSPEC_HIDDEN; +jsstr_t *jsstr_null_bstr(void) DECLSPEC_HIDDEN; +BOOL is_null_bstr(jsstr_t*) DECLSPEC_HIDDEN; + BOOL init_strings(void) DECLSPEC_HIDDEN; void free_strings(void) DECLSPEC_HIDDEN; diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index 60ca4740de3..87bad26fe95 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -294,11 +294,13 @@ HRESULT variant_to_jsval(VARIANT *var, jsval_t *r) case VT_BSTR: { jsstr_t *str; - str = jsstr_alloc_len(V_BSTR(var), SysStringLen(V_BSTR(var))); - if(!str) - return E_OUTOFMEMORY; - if(!V_BSTR(var)) - str->length_flags |= JSSTR_FLAG_NULLBSTR; + if(V_BSTR(var)) { + str = jsstr_alloc_len(V_BSTR(var), SysStringLen(V_BSTR(var))); + if(!str) + return E_OUTOFMEMORY; + }else { + str = jsstr_null_bstr(); + } *r = jsval_string(str); return S_OK; @@ -351,7 +353,7 @@ HRESULT jsval_to_variant(jsval_t val, VARIANT *retv) jsstr_t *str = get_string(val); V_VT(retv) = VT_BSTR; - if(str->length_flags & JSSTR_FLAG_NULLBSTR) { + if(is_null_bstr(str)) { V_BSTR(retv) = NULL; }else { V_BSTR(retv) = SysAllocStringLen(NULL, jsstr_length(str)); @@ -913,7 +915,7 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY if(FAILED(hres)) break; - if(str->length_flags & JSSTR_FLAG_NULLBSTR) { + if(is_null_bstr(str)) { V_BSTR(dst) = NULL; break; }