From f0c0c14241219c302385088977eecdd03064f793 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 18 Dec 2012 11:16:24 +0100 Subject: [PATCH] jscript: Moved string concatenation to helper function. --- dlls/jscript/engine.c | 15 +++------------ dlls/jscript/jsstr.c | 19 +++++++++++++++++++ dlls/jscript/jsstr.h | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 489aef6774f..eb15be43ace 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -1447,22 +1447,13 @@ static HRESULT add_eval(script_ctx_t *ctx, jsval_t lval, jsval_t rval, jsval_t * hres = to_string(ctx, r, &rstr); if(SUCCEEDED(hres)) { - unsigned len1, len2; jsstr_t *ret_str; - len1 = jsstr_length(lstr); - len2 = jsstr_length(rstr); - - ret_str = jsstr_alloc_buf(len1+len2); - if(ret_str) { - if(len1) - memcpy(ret_str->str, lstr->str, len1*sizeof(WCHAR)); - if(len2) - memcpy(ret_str->str+len1, rstr->str, len2*sizeof(WCHAR)); + ret_str = jsstr_concat(lstr, rstr); + if(ret_str) *ret = jsval_string(ret_str); - }else { + else hres = E_OUTOFMEMORY; - } } jsstr_release(lstr); diff --git a/dlls/jscript/jsstr.c b/dlls/jscript/jsstr.c index 3586dad0584..aad7af29cc4 100644 --- a/dlls/jscript/jsstr.c +++ b/dlls/jscript/jsstr.c @@ -66,6 +66,25 @@ int jsstr_cmp(jsstr_t *str1, jsstr_t *str2) return ret; } +jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2) +{ + unsigned len1, len2; + jsstr_t *ret; + + len1 = jsstr_length(str1); + len2 = jsstr_length(str2); + + ret = jsstr_alloc_buf(len1+len2); + if(!ret) + return NULL; + + if(len1) + memcpy(ret->str, str1->str, len1*sizeof(WCHAR)); + if(len2) + memcpy(ret->str+len1, str2->str, len2*sizeof(WCHAR)); + return ret; +} + static jsstr_t *empty_str, *nan_str; jsstr_t *jsstr_nan(void) diff --git a/dlls/jscript/jsstr.h b/dlls/jscript/jsstr.h index ca3b5d9e3b1..8ac741084cb 100644 --- a/dlls/jscript/jsstr.h +++ b/dlls/jscript/jsstr.h @@ -60,6 +60,7 @@ static inline BOOL jsstr_eq(jsstr_t *str1, jsstr_t *str2) } int jsstr_cmp(jsstr_t*,jsstr_t*) DECLSPEC_HIDDEN; +jsstr_t *jsstr_concat(jsstr_t*,jsstr_t*) DECLSPEC_HIDDEN; jsstr_t *jsstr_nan(void) DECLSPEC_HIDDEN; jsstr_t *jsstr_empty(void) DECLSPEC_HIDDEN;