ReactOS 0.4.16-dev-303-g11d5cb8
jsstr.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _jsstr_t
 
struct  jsstr_inline_t
 
struct  jsstr_heap_t
 
struct  jsstr_rope_t
 

Macros

#define JSSTR_LENGTH_SHIFT   4
 
#define JSSTR_MAX_LENGTH   ((1 << (32-JSSTR_LENGTH_SHIFT))-1)
 
#define JSSTR_FLAGS_MASK   ((1 << JSSTR_LENGTH_SHIFT)-1)
 
#define JSSTR_FLAG_LBIT   1
 
#define JSSTR_FLAG_FLAT   2
 
#define JSSTR_FLAG_TAG_MASK   3
 

Enumerations

enum  jsstr_tag_t { JSSTR_INLINE = JSSTR_FLAG_FLAT , JSSTR_HEAP = JSSTR_FLAG_FLAT|JSSTR_FLAG_LBIT , JSSTR_ROPE = JSSTR_FLAG_LBIT }
 

Functions

static unsigned jsstr_length (jsstr_t *str)
 
static jsstr_tag_t jsstr_tag (jsstr_t *str)
 
static BOOL jsstr_is_inline (jsstr_t *str)
 
static BOOL jsstr_is_heap (jsstr_t *str)
 
static BOOL jsstr_is_rope (jsstr_t *str)
 
jsstr_tjsstr_alloc_len (const WCHAR *, unsigned) DECLSPEC_HIDDEN
 
jsstr_tjsstr_alloc_buf (unsigned, WCHAR **) DECLSPEC_HIDDEN
 
static jsstr_tjsstr_alloc (const WCHAR *str)
 
void jsstr_free (jsstr_t *) DECLSPEC_HIDDEN
 
static void jsstr_release (jsstr_t *str)
 
static jsstr_tjsstr_addref (jsstr_t *str)
 
static jsstr_inline_tjsstr_as_inline (jsstr_t *str)
 
static jsstr_heap_tjsstr_as_heap (jsstr_t *str)
 
static jsstr_rope_tjsstr_as_rope (jsstr_t *str)
 
const WCHARjsstr_rope_flatten (jsstr_rope_t *) DECLSPEC_HIDDEN
 
static const WCHARjsstr_flatten (jsstr_t *str)
 
void jsstr_extract (jsstr_t *, unsigned, unsigned, WCHAR *) DECLSPEC_HIDDEN
 
static unsigned jsstr_flush (jsstr_t *str, WCHAR *buf)
 
static jsstr_tjsstr_substr (jsstr_t *str, unsigned off, unsigned len)
 
int jsstr_cmp (jsstr_t *, jsstr_t *) DECLSPEC_HIDDEN
 
static BOOL jsstr_eq (jsstr_t *left, jsstr_t *right)
 
jsstr_tjsstr_concat (jsstr_t *, jsstr_t *) DECLSPEC_HIDDEN
 
jsstr_tjsstr_nan (void) DECLSPEC_HIDDEN
 
jsstr_tjsstr_empty (void) DECLSPEC_HIDDEN
 
jsstr_tjsstr_undefined (void) DECLSPEC_HIDDEN
 
jsstr_tjsstr_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
 
const chardebugstr_jsstr (jsstr_t *) DECLSPEC_HIDDEN
 

Macro Definition Documentation

◆ JSSTR_FLAG_FLAT

#define JSSTR_FLAG_FLAT   2

Definition at line 49 of file jsstr.h.

◆ JSSTR_FLAG_LBIT

#define JSSTR_FLAG_LBIT   1

Definition at line 48 of file jsstr.h.

◆ JSSTR_FLAG_TAG_MASK

#define JSSTR_FLAG_TAG_MASK   3

Definition at line 50 of file jsstr.h.

◆ JSSTR_FLAGS_MASK

#define JSSTR_FLAGS_MASK   ((1 << JSSTR_LENGTH_SHIFT)-1)

Definition at line 46 of file jsstr.h.

◆ JSSTR_LENGTH_SHIFT

#define JSSTR_LENGTH_SHIFT   4

Definition at line 44 of file jsstr.h.

◆ JSSTR_MAX_LENGTH

#define JSSTR_MAX_LENGTH   ((1 << (32-JSSTR_LENGTH_SHIFT))-1)

Definition at line 45 of file jsstr.h.

Enumeration Type Documentation

◆ jsstr_tag_t

Enumerator
JSSTR_INLINE 
JSSTR_HEAP 
JSSTR_ROPE 

Definition at line 52 of file jsstr.h.

52 {
#define JSSTR_FLAG_LBIT
Definition: jsstr.h:48
#define JSSTR_FLAG_FLAT
Definition: jsstr.h:49
jsstr_tag_t
Definition: jsstr.h:52
@ JSSTR_INLINE
Definition: jsstr.h:53
@ JSSTR_HEAP
Definition: jsstr.h:54
@ JSSTR_ROPE
Definition: jsstr.h:55

Function Documentation

◆ debugstr_jsstr()

const char * debugstr_jsstr ( jsstr_t str)

Definition at line 37 of file jsstr.c.

38{
42}
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:296
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLint left
Definition: glext.h:7726
const char * debugstr_jsstr(jsstr_t *str)
Definition: jsstr.c:37
static jsstr_inline_t * jsstr_as_inline(jsstr_t *str)
Definition: jsstr.h:122
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:58
static jsstr_heap_t * jsstr_as_heap(jsstr_t *str)
Definition: jsstr.h:127
static BOOL jsstr_is_heap(jsstr_t *str)
Definition: jsstr.h:73
static BOOL jsstr_is_inline(jsstr_t *str)
Definition: jsstr.h:68
static jsstr_rope_t * jsstr_as_rope(jsstr_t *str)
Definition: jsstr.h:132
#define debugstr_wn
Definition: kernel32.h:33
const WCHAR * str

Referenced by array_join(), debugstr_jsstr(), debugstr_jsval(), dump_instr_arg(), interp_obj_prop(), interp_regexp(), interp_str(), interp_throw_type(), JSGlobal_decodeURI(), JSGlobal_encodeURI(), String_idx_get(), and String_replace().

◆ free_strings()

void free_strings ( void  )

Definition at line 325 of file jsstr.c.

326{
327 if(empty_str)
329 if(nan_str)
331 if(undefined_str)
333 if(null_bstr_str)
335}
static jsstr_t * undefined_str
Definition: jsstr.c:281
static jsstr_t * null_bstr_str
Definition: jsstr.c:281
static jsstr_t * empty_str
Definition: jsstr.c:281
static jsstr_t * nan_str
Definition: jsstr.c:281
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:110

Referenced by DllMain().

◆ init_strings()

BOOL init_strings ( void  )

Definition at line 308 of file jsstr.c.

309{
310 static const WCHAR NaNW[] = { 'N','a','N',0 };
311 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
312 WCHAR *ptr;
313
314 if(!(empty_str = jsstr_alloc_buf(0, &ptr)))
315 return FALSE;
316 if(!(nan_str = jsstr_alloc(NaNW)))
317 return FALSE;
319 return FALSE;
320 if(!(null_bstr_str = jsstr_alloc_buf(0, &ptr)))
321 return FALSE;
322 return TRUE;
323}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR undefinedW[]
Definition: engine.c:39
static const WCHAR NaNW[]
Definition: global.c:34
jsstr_t * jsstr_alloc_buf(unsigned len, WCHAR **buf)
Definition: jsstr.c:69
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:103
static PVOID ptr
Definition: dispmode.c:27
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DllMain().

◆ is_null_bstr()

BOOL is_null_bstr ( jsstr_t str)

Definition at line 303 of file jsstr.c.

304{
305 return str == null_bstr_str;
306}

Referenced by jsval_to_variant(), and variant_change_type().

◆ jsstr_addref()

◆ jsstr_alloc()

◆ jsstr_alloc_buf()

jsstr_t * jsstr_alloc_buf ( unsigned  len,
WCHAR **  buf 
)

◆ jsstr_alloc_len()

jsstr_t * jsstr_alloc_len ( const WCHAR buf,
unsigned  len 
)

◆ jsstr_as_heap()

static jsstr_heap_t * jsstr_as_heap ( jsstr_t str)
inlinestatic

Definition at line 127 of file jsstr.h.

128{
130}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by debugstr_jsstr(), jsstr_cmp_str(), jsstr_extract(), jsstr_flatten(), jsstr_flush(), jsstr_free(), jsstr_rope_flatten(), and jsstr_try_flat().

◆ jsstr_as_inline()

static jsstr_inline_t * jsstr_as_inline ( jsstr_t str)
inlinestatic

◆ jsstr_as_rope()

static jsstr_rope_t * jsstr_as_rope ( jsstr_t str)
inlinestatic

◆ jsstr_cmp()

int jsstr_cmp ( jsstr_t str1,
jsstr_t str2 
)

Definition at line 189 of file jsstr.c.

190{
191 unsigned len1 = jsstr_length(str1);
192 unsigned len2 = jsstr_length(str2);
193 const WCHAR *str;
194 int ret;
195
196 str = jsstr_try_flat(str2);
197 if(str) {
198 ret = jsstr_cmp_str(str1, str, min(len1, len2));
199 return ret || len1 == len2 ? ret : -1;
200 }
201
202 str = jsstr_try_flat(str1);
203 if(str) {
204 ret = jsstr_cmp_str(str2, str, min(len1, len2));
205 return ret || len1 == len2 ? -ret : 1;
206 }
207
208 return ropes_cmp(jsstr_as_rope(str1), jsstr_as_rope(str2));
209}
static int ropes_cmp(jsstr_rope_t *left, jsstr_rope_t *right)
Definition: jsstr.c:156
static int jsstr_cmp_str(jsstr_t *jsstr, const WCHAR *str, unsigned len)
Definition: jsstr.c:128
static const WCHAR * jsstr_try_flat(jsstr_t *str)
Definition: jsstr.c:182
#define min(a, b)
Definition: monoChain.cc:55

Referenced by jsstr_eq(), less_eval(), and sort_cmp().

◆ jsstr_concat()

jsstr_t * jsstr_concat ( jsstr_t str1,
jsstr_t str2 
)

Definition at line 211 of file jsstr.c.

212{
213 unsigned len1, len2;
214 jsstr_t *ret;
215 WCHAR *ptr;
216
217 len1 = jsstr_length(str1);
218 if(!len1)
219 return jsstr_addref(str2);
220
221 len2 = jsstr_length(str2);
222 if(!len2)
223 return jsstr_addref(str1);
224
225 if(len1 + len2 >= JSSTR_SHORT_STRING_LENGTH) {
226 unsigned depth, depth2;
228
229 depth = jsstr_is_rope(str1) ? jsstr_as_rope(str1)->depth : 0;
230 depth2 = jsstr_is_rope(str2) ? jsstr_as_rope(str2)->depth : 0;
231 if(depth2 > depth)
232 depth = depth2;
233
235 if(len1+len2 > JSSTR_MAX_LENGTH)
236 return NULL;
237
238 rope = heap_alloc(sizeof(*rope));
239 if(!rope)
240 return NULL;
241
242 jsstr_init(&rope->str, len1+len2, JSSTR_ROPE);
243 rope->left = jsstr_addref(str1);
244 rope->right = jsstr_addref(str2);
245 rope->depth = depth;
246 return &rope->str;
247 }
248 }
249
250 ret = jsstr_alloc_buf(len1+len2, &ptr);
251 if(!ret)
252 return NULL;
253
254 jsstr_flush(str1, ptr);
255 jsstr_flush(str2, ptr+len1);
256 return ret;
257
258}
Definition: _rope.h:1087
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define JSSTR_SHORT_STRING_LENGTH
Definition: jsstr.c:30
#define JSSTR_MAX_ROPE_DEPTH
Definition: jsstr.c:35
static jsstr_t * jsstr_addref(jsstr_t *str)
Definition: jsstr.h:116
static BOOL jsstr_is_rope(jsstr_t *str)
Definition: jsstr.h:78
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:148
unsigned depth
Definition: jsstr.h:97

Referenced by add_eval(), and String_concat().

◆ jsstr_empty()

◆ jsstr_eq()

static BOOL jsstr_eq ( jsstr_t left,
jsstr_t right 
)
inlinestatic

Definition at line 176 of file jsstr.h.

177{
179}
GLdouble GLdouble right
Definition: glext.h:10859
int jsstr_cmp(jsstr_t *, jsstr_t *) DECLSPEC_HIDDEN
Definition: jsstr.c:189

Referenced by jsval_strict_equal().

◆ jsstr_extract()

void jsstr_extract ( jsstr_t str,
unsigned  off,
unsigned  len,
WCHAR buf 
)

Definition at line 113 of file jsstr.c.

114{
115 switch(jsstr_tag(str)) {
116 case JSSTR_INLINE:
117 memcpy(buf, jsstr_as_inline(str)->buf+off, len*sizeof(WCHAR));
118 return;
119 case JSSTR_HEAP:
120 memcpy(buf, jsstr_as_heap(str)->buf+off, len*sizeof(WCHAR));
121 return;
122 case JSSTR_ROPE:
124 return;
125 }
126}
static void jsstr_rope_extract(jsstr_rope_t *str, unsigned off, unsigned len, WCHAR *buf)
Definition: jsstr.c:98
static jsstr_tag_t jsstr_tag(jsstr_t *str)
Definition: jsstr.h:63

Referenced by JSON_stringify(), jsstr_rope_extract(), jsstr_substr(), and String_charCodeAt().

◆ jsstr_flatten()

◆ jsstr_flush()

◆ jsstr_free()

void jsstr_free ( jsstr_t str)

Definition at line 44 of file jsstr.c.

45{
46 switch(jsstr_tag(str)) {
47 case JSSTR_HEAP:
49 break;
50 case JSSTR_ROPE: {
52 jsstr_release(rope->left);
53 jsstr_release(rope->right);
54 break;
55 }
56 case JSSTR_INLINE:
57 break;
58 }
59
61}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76

Referenced by jsstr_release().

◆ jsstr_is_heap()

static BOOL jsstr_is_heap ( jsstr_t str)
inlinestatic

Definition at line 73 of file jsstr.h.

74{
75 return jsstr_tag(str) == JSSTR_HEAP;
76}

Referenced by debugstr_jsstr(), jsstr_flatten(), jsstr_flush(), and jsstr_try_flat().

◆ jsstr_is_inline()

static BOOL jsstr_is_inline ( jsstr_t str)
inlinestatic

Definition at line 68 of file jsstr.h.

69{
70 return jsstr_tag(str) == JSSTR_INLINE;
71}

Referenced by debugstr_jsstr(), jsstr_flatten(), jsstr_flush(), and jsstr_try_flat().

◆ jsstr_is_rope()

static BOOL jsstr_is_rope ( jsstr_t str)
inlinestatic

Definition at line 78 of file jsstr.h.

79{
80 return jsstr_tag(str) == JSSTR_ROPE;
81}

Referenced by jsstr_concat().

◆ jsstr_length()

◆ jsstr_nan()

◆ jsstr_null_bstr()

jsstr_t * jsstr_null_bstr ( void  )

Definition at line 298 of file jsstr.c.

299{
301}

Referenced by variant_to_jsval().

◆ jsstr_release()

static void jsstr_release ( jsstr_t str)
inlinestatic

Definition at line 110 of file jsstr.h.

111{
112 if(!--str->ref)
114}
void jsstr_free(jsstr_t *) DECLSPEC_HIDDEN
Definition: jsstr.c:44

Referenced by ActiveXObject_value(), add_eval(), array_join(), Array_join(), construct_function(), create_match_array(), DateConstr_parse(), do_attribute_tag_format(), do_attributeless_tag_format(), do_regexp_match_next(), error_constr(), Error_toString(), free_strings(), Function_toString(), get_string_flat_val(), init_error_constr(), interp_array(), interp_delete(), interp_forin(), interp_in(), interp_memberid(), JSGlobal_decodeURI(), JSGlobal_decodeURIComponent(), JSGlobal_encodeURI(), JSGlobal_encodeURIComponent(), JSGlobal_escape(), JSGlobal_parseFloat(), JSGlobal_parseInt(), JSGlobal_unescape(), JSON_parse(), jsstr_free(), jsstr_rope_flatten(), jsval_release(), less_eval(), Number_toExponential(), Number_toFixed(), Number_toPrecision(), Number_toString(), Object_defineProperty(), Object_getOwnPropertyDescriptor(), Object_hasOwnProperty(), Object_propertyIsEnumerable(), RegExp_destructor(), RegExp_exec(), regexp_string_match(), RegExp_test(), release_bytecode(), rep_call(), run_exec(), script_release(), sort_cmp(), String_charAt(), String_charCodeAt(), String_concat(), String_destructor(), String_indexOf(), String_lastIndexOf(), String_match(), String_replace(), String_search(), String_slice(), String_split(), String_substr(), String_substring(), String_toLowerCase(), String_toUpperCase(), String_trim(), StringConstr_fromCharCode(), StringConstr_value(), stringify(), throw_error(), and to_flat_string().

◆ jsstr_rope_flatten()

const WCHAR * jsstr_rope_flatten ( jsstr_rope_t str)

Definition at line 262 of file jsstr.c.

263{
264 WCHAR *buf;
265
266 buf = heap_alloc((jsstr_length(&str->str)+1) * sizeof(WCHAR));
267 if(!buf)
268 return NULL;
269
270 jsstr_flush(str->left, buf);
271 jsstr_flush(str->right, buf+jsstr_length(str->left));
272 buf[jsstr_length(&str->str)] = 0;
273
274 /* Trasform to heap string */
275 jsstr_release(str->left);
276 jsstr_release(str->right);
277 str->str.length_flags |= JSSTR_FLAG_FLAT;
278 return jsstr_as_heap(&str->str)->buf = buf;
279}

Referenced by jsstr_flatten().

◆ jsstr_substr()

static jsstr_t * jsstr_substr ( jsstr_t str,
unsigned  off,
unsigned  len 
)
inlinestatic

Definition at line 163 of file jsstr.h.

164{
165 jsstr_t *ret;
166 WCHAR *ptr;
167
169 if(ret)
170 jsstr_extract(str, off, len, ptr);
171 return ret;
172}
jsstr_t * jsstr_alloc_buf(unsigned, WCHAR **) DECLSPEC_HIDDEN
Definition: jsstr.c:69
void jsstr_extract(jsstr_t *, unsigned, unsigned, WCHAR *) DECLSPEC_HIDDEN
Definition: jsstr.c:113

Referenced by create_match_array(), global_idx(), regexp_string_match(), RegExpConstr_get_leftContext(), RegExpConstr_get_rightContext(), rep_call(), String_charAt(), String_idx_get(), String_slice(), String_substr(), and String_substring().

◆ jsstr_tag()

static jsstr_tag_t jsstr_tag ( jsstr_t str)
inlinestatic

Definition at line 63 of file jsstr.h.

64{
65 return str->length_flags & JSSTR_FLAG_TAG_MASK;
66}
#define JSSTR_FLAG_TAG_MASK
Definition: jsstr.h:50

Referenced by jsstr_cmp_str(), jsstr_extract(), jsstr_free(), jsstr_is_heap(), jsstr_is_inline(), and jsstr_is_rope().

◆ jsstr_undefined()