Commit 2ac35ac4 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Use single string instance for strings representing NULL BSTR instead of a flag.

parent cd55afec
...@@ -277,7 +277,7 @@ const WCHAR *jsstr_rope_flatten(jsstr_rope_t *str) ...@@ -277,7 +277,7 @@ const WCHAR *jsstr_rope_flatten(jsstr_rope_t *str)
return jsstr_as_heap(&str->str)->buf = buf; 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) jsstr_t *jsstr_nan(void)
{ {
...@@ -294,6 +294,16 @@ jsstr_t *jsstr_undefined(void) ...@@ -294,6 +294,16 @@ jsstr_t *jsstr_undefined(void)
return jsstr_addref(undefined_str); 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) BOOL init_strings(void)
{ {
static const WCHAR NaNW[] = { 'N','a','N',0 }; static const WCHAR NaNW[] = { 'N','a','N',0 };
...@@ -305,12 +315,19 @@ BOOL init_strings(void) ...@@ -305,12 +315,19 @@ BOOL init_strings(void)
return FALSE; return FALSE;
if(!(undefined_str = jsstr_alloc(undefinedW))) if(!(undefined_str = jsstr_alloc(undefinedW)))
return FALSE; return FALSE;
if(!jsstr_alloc_buf(0, &null_bstr_str))
return FALSE;
return TRUE; return TRUE;
} }
void free_strings(void) void free_strings(void)
{ {
if(empty_str)
jsstr_release(empty_str); jsstr_release(empty_str);
if(nan_str)
jsstr_release(nan_str); jsstr_release(nan_str);
if(undefined_str)
jsstr_release(undefined_str); jsstr_release(undefined_str);
if(null_bstr_str)
jsstr_release(null_bstr_str);
} }
...@@ -17,7 +17,7 @@ ...@@ -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: * representation may be:
* *
* - inline string - string bytes directly follow string headers. * - inline string - string bytes directly follow string headers.
...@@ -42,8 +42,6 @@ struct _jsstr_t { ...@@ -42,8 +42,6 @@ struct _jsstr_t {
#define JSSTR_MAX_LENGTH (1 << (32-JSSTR_LENGTH_SHIFT)) #define JSSTR_MAX_LENGTH (1 << (32-JSSTR_LENGTH_SHIFT))
#define JSSTR_FLAGS_MASK ((1 << JSSTR_LENGTH_SHIFT)-1) #define JSSTR_FLAGS_MASK ((1 << JSSTR_LENGTH_SHIFT)-1)
#define JSSTR_FLAG_NULLBSTR 4
#define JSSTR_FLAG_LBIT 1 #define JSSTR_FLAG_LBIT 1
#define JSSTR_FLAG_FLAT 2 #define JSSTR_FLAG_FLAT 2
#define JSSTR_FLAG_TAG_MASK 3 #define JSSTR_FLAG_TAG_MASK 3
...@@ -187,6 +185,9 @@ jsstr_t *jsstr_nan(void) DECLSPEC_HIDDEN; ...@@ -187,6 +185,9 @@ 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; 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; BOOL init_strings(void) DECLSPEC_HIDDEN;
void free_strings(void) DECLSPEC_HIDDEN; void free_strings(void) DECLSPEC_HIDDEN;
......
...@@ -294,11 +294,13 @@ HRESULT variant_to_jsval(VARIANT *var, jsval_t *r) ...@@ -294,11 +294,13 @@ HRESULT variant_to_jsval(VARIANT *var, jsval_t *r)
case VT_BSTR: { case VT_BSTR: {
jsstr_t *str; jsstr_t *str;
if(V_BSTR(var)) {
str = jsstr_alloc_len(V_BSTR(var), SysStringLen(V_BSTR(var))); str = jsstr_alloc_len(V_BSTR(var), SysStringLen(V_BSTR(var)));
if(!str) if(!str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if(!V_BSTR(var)) }else {
str->length_flags |= JSSTR_FLAG_NULLBSTR; str = jsstr_null_bstr();
}
*r = jsval_string(str); *r = jsval_string(str);
return S_OK; return S_OK;
...@@ -351,7 +353,7 @@ HRESULT jsval_to_variant(jsval_t val, VARIANT *retv) ...@@ -351,7 +353,7 @@ HRESULT jsval_to_variant(jsval_t val, VARIANT *retv)
jsstr_t *str = get_string(val); jsstr_t *str = get_string(val);
V_VT(retv) = VT_BSTR; V_VT(retv) = VT_BSTR;
if(str->length_flags & JSSTR_FLAG_NULLBSTR) { if(is_null_bstr(str)) {
V_BSTR(retv) = NULL; V_BSTR(retv) = NULL;
}else { }else {
V_BSTR(retv) = SysAllocStringLen(NULL, jsstr_length(str)); 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 ...@@ -913,7 +915,7 @@ HRESULT variant_change_type(script_ctx_t *ctx, VARIANT *dst, VARIANT *src, VARTY
if(FAILED(hres)) if(FAILED(hres))
break; break;
if(str->length_flags & JSSTR_FLAG_NULLBSTR) { if(is_null_bstr(str)) {
V_BSTR(dst) = NULL; V_BSTR(dst) = NULL;
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment