mirror of
https://github.com/reactos/wine.git
synced 2024-11-25 04:39:45 +00:00
jscript: Moved string buffer to separated struct from jsstr_t.
This commit is contained in:
parent
c79180a978
commit
29d9d668f7
@ -22,25 +22,25 @@
|
||||
|
||||
const char *debugstr_jsstr(jsstr_t *str)
|
||||
{
|
||||
return debugstr_wn(str->str, jsstr_length(str));
|
||||
return debugstr_wn(jsstr_as_inline(str)->buf, jsstr_length(str));
|
||||
}
|
||||
|
||||
WCHAR *jsstr_alloc_buf(unsigned len, jsstr_t **r)
|
||||
{
|
||||
jsstr_t *ret;
|
||||
jsstr_inline_t *ret;
|
||||
|
||||
if(len > JSSTR_MAX_LENGTH)
|
||||
return NULL;
|
||||
|
||||
ret = heap_alloc(FIELD_OFFSET(jsstr_t, str[len+1]));
|
||||
ret = heap_alloc(FIELD_OFFSET(jsstr_inline_t, buf[len+1]));
|
||||
if(!ret)
|
||||
return NULL;
|
||||
|
||||
ret->length_flags = len << JSSTR_LENGTH_SHIFT;
|
||||
ret->ref = 1;
|
||||
ret->str[len] = 0;
|
||||
*r = ret;
|
||||
return ret->str;
|
||||
ret->str.length_flags = len << JSSTR_LENGTH_SHIFT;
|
||||
ret->str.ref = 1;
|
||||
ret->buf[len] = 0;
|
||||
*r = &ret->str;
|
||||
return ret->buf;
|
||||
}
|
||||
|
||||
jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len)
|
||||
@ -61,7 +61,7 @@ int jsstr_cmp(jsstr_t *str1, jsstr_t *str2)
|
||||
int len2 = jsstr_length(str2);
|
||||
int ret;
|
||||
|
||||
ret = memcmp(str1->str, str2->str, min(len1, len2)*sizeof(WCHAR));
|
||||
ret = memcmp(jsstr_as_inline(str1)->buf, jsstr_as_inline(str2)->buf, min(len1, len2)*sizeof(WCHAR));
|
||||
if(!ret)
|
||||
ret = len1 - len2;
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
struct _jsstr_t {
|
||||
unsigned length_flags;
|
||||
unsigned ref;
|
||||
WCHAR str[1];
|
||||
};
|
||||
|
||||
#define JSSTR_LENGTH_SHIFT 4
|
||||
@ -33,6 +32,11 @@ static inline unsigned jsstr_length(jsstr_t *str)
|
||||
return str->length_flags >> JSSTR_LENGTH_SHIFT;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
jsstr_t str;
|
||||
WCHAR buf[1];
|
||||
} jsstr_inline_t;
|
||||
|
||||
jsstr_t *jsstr_alloc_len(const WCHAR*,unsigned) DECLSPEC_HIDDEN;
|
||||
WCHAR *jsstr_alloc_buf(unsigned,jsstr_t**) DECLSPEC_HIDDEN;
|
||||
|
||||
@ -53,27 +57,32 @@ static inline jsstr_t *jsstr_addref(jsstr_t *str)
|
||||
return str;
|
||||
}
|
||||
|
||||
static inline jsstr_inline_t *jsstr_as_inline(jsstr_t *str)
|
||||
{
|
||||
return CONTAINING_RECORD(str, jsstr_inline_t, str);
|
||||
}
|
||||
|
||||
/* This will be failable in the future. */
|
||||
static inline const WCHAR *jsstr_flatten(jsstr_t *str)
|
||||
{
|
||||
return str->str;
|
||||
return jsstr_as_inline(str)->buf;
|
||||
}
|
||||
|
||||
static inline BOOL jsstr_eq(jsstr_t *str1, jsstr_t *str2)
|
||||
{
|
||||
unsigned len = jsstr_length(str1);
|
||||
return len == jsstr_length(str2) && !memcmp(str1->str, str2->str, len*sizeof(WCHAR));
|
||||
return len == jsstr_length(str2) && !memcmp(jsstr_as_inline(str1)->buf, jsstr_as_inline(str2)->buf, len*sizeof(WCHAR));
|
||||
}
|
||||
|
||||
static inline void jsstr_extract(jsstr_t *str, unsigned off, unsigned len, WCHAR *buf)
|
||||
{
|
||||
memcpy(buf, str->str+off, len*sizeof(WCHAR));
|
||||
memcpy(buf, jsstr_as_inline(str)->buf+off, len*sizeof(WCHAR));
|
||||
}
|
||||
|
||||
static inline unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
|
||||
{
|
||||
unsigned len = jsstr_length(str);
|
||||
memcpy(buf, str->str, len*sizeof(WCHAR));
|
||||
memcpy(buf, jsstr_as_inline(str)->buf, len*sizeof(WCHAR));
|
||||
return len;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user