本文整理汇总了C++中JSString::flatSetAtomized方法的典型用法代码示例。如果您正苦于以下问题:C++ JSString::flatSetAtomized方法的具体用法?C++ JSString::flatSetAtomized怎么用?C++ JSString::flatSetAtomized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSString
的用法示例。
在下文中一共展示了JSString::flatSetAtomized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
//.........这里部分代码省略.........
}
/*
* Here we know that JSString::intStringTable covers only 256 (or at least
* not 1000 or more) chars. We rely on order here to resolve the unit vs.
* int string atom identity issue by giving priority to unit strings for
* '0' through '9' (see JSString::intString in jsstrinlines.h).
*/
JS_STATIC_ASSERT(INT_STRING_LIMIT <= 999);
if (2 <= length && length <= 3) {
const jschar *chars = str->chars();
if ('1' <= chars[0] && chars[0] <= '9' &&
'0' <= chars[1] && chars[1] <= '9' &&
(length == 2 || ('0' <= chars[2] && chars[2] <= '9'))) {
jsint i = (chars[0] - '0') * 10 + chars[1] - '0';
if (length == 3)
i = i * 10 + chars[2] - '0';
if (jsuint(i) < INT_STRING_LIMIT)
return (JSAtom *) STRING_TO_JSVAL(JSString::intString(i));
}
}
state = &cx->runtime->atomState;
table = &state->stringAtoms;
JS_LOCK(cx, &state->lock);
entry = TO_ATOM_ENTRY(JS_DHashTableOperate(table, str, JS_DHASH_ADD));
if (!entry)
goto failed_hash_add;
if (entry->keyAndFlags != 0) {
key = (JSString *)ATOM_ENTRY_KEY(entry);
} else {
/*
* We created a new hashtable entry. Unless str is already allocated
* from the GC heap and flat, we have to release state->lock as
* string construction is a complex operation. For example, it can
* trigger GC which may rehash the table and make the entry invalid.
*/
++table->generation;
if (!(flags & ATOM_TMPSTR) && str->isFlat()) {
str->flatClearMutable();
key = str;
} else {
gen = table->generation;
JS_UNLOCK(cx, &state->lock);
if (flags & ATOM_TMPSTR) {
if (flags & ATOM_NOCOPY) {
key = js_NewString(cx, str->flatChars(), str->flatLength());
if (!key)
return NULL;
/* Finish handing off chars to the GC'ed key string. */
str->mChars = NULL;
} else {
key = js_NewStringCopyN(cx, str->flatChars(), str->flatLength());
if (!key)
return NULL;
}
} else {
JS_ASSERT(str->isDependent());
if (!js_UndependString(cx, str))
return NULL;
key = str;
}
JS_LOCK(cx, &state->lock);
if (table->generation == gen) {
JS_ASSERT(entry->keyAndFlags == 0);
} else {
entry = TO_ATOM_ENTRY(JS_DHashTableOperate(table, key,
JS_DHASH_ADD));
if (!entry)
goto failed_hash_add;
if (entry->keyAndFlags != 0) {
key = (JSString *)ATOM_ENTRY_KEY(entry);
goto finish;
}
++table->generation;
}
}
INIT_ATOM_ENTRY(entry, key);
key->flatSetAtomized();
}
finish:
ADD_ATOM_ENTRY_FLAGS(entry, flags & (ATOM_PINNED | ATOM_INTERNED));
JS_ASSERT(key->isAtomized());
v = STRING_TO_JSVAL(key);
cx->weakRoots.lastAtom = v;
JS_UNLOCK(cx, &state->lock);
return (JSAtom *)v;
failed_hash_add:
JS_UNLOCK(cx, &state->lock);
JS_ReportOutOfMemory(cx);
return NULL;
}