当前位置: 首页>>代码示例>>C++>>正文


C++ JSLinearString::flatClearExtensible方法代码示例

本文整理汇总了C++中JSLinearString::flatClearExtensible方法的典型用法代码示例。如果您正苦于以下问题:C++ JSLinearString::flatClearExtensible方法的具体用法?C++ JSLinearString::flatClearExtensible怎么用?C++ JSLinearString::flatClearExtensible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSLinearString的用法示例。


在下文中一共展示了JSLinearString::flatClearExtensible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: STRING_TO_ATOM

JSAtom *
js_AtomizeString(JSContext *cx, JSString *strArg, uintN flags)
{
    JS_ASSERT(!(flags & ~(ATOM_PINNED|ATOM_INTERNED|ATOM_TMPSTR|ATOM_NOCOPY)));
    JS_ASSERT_IF(flags & ATOM_NOCOPY, flags & ATOM_TMPSTR);

    if (strArg->isAtomized())
        return STRING_TO_ATOM(strArg);

    JSLinearString *str = strArg->ensureLinear(cx);
    if (!str)
        return NULL;

    const jschar *chars = str->chars();
    size_t length = str->length();

    JSString *staticStr = JSString::lookupStaticString(chars, length);
    if (staticStr)
        return STRING_TO_ATOM(staticStr);

    JSAtomState *state = &cx->runtime->atomState;
    AtomSet &atoms = state->atoms;

    AutoLockAtomsCompartment lock(cx);
    AtomSet::AddPtr p = atoms.lookupForAdd(str);

    /* Hashing the string should have flattened it if it was a rope. */
    JS_ASSERT(str->isFlat() || str->isDependent());

    JSLinearString *key;
    if (p) {
        key = AtomEntryToKey(*p);
    } else {
        /*
         * Ensure that any atomized string lives only in the default
         * compartment.
         */
        bool needNewString = !!(flags & ATOM_TMPSTR) ||
                             str->asCell()->compartment() != cx->runtime->atomsCompartment;

        /*
         * Unless str is already comes from the default compartment and flat,
         * we have to relookup the key as the last ditch GC invoked from the
         * string allocation or OOM handling may unlock the default
         * compartment lock.
         */
        if (!needNewString && str->isFlat()) {
            str->flatClearExtensible();
            key = str;
            atoms.add(p, StringToInitialAtomEntry(key));
        } else {
            if (needNewString) {
                SwitchToCompartment sc(cx, cx->runtime->atomsCompartment);
                if (flags & ATOM_NOCOPY) {
                    key = js_NewString(cx, const_cast<jschar *>(str->flatChars()), length);
                    if (!key)
                        return NULL;

                    /* Finish handing off chars to the GC'ed key string. */
                    JS_ASSERT(flags & ATOM_TMPSTR);
                    str->u.chars = NULL;
                } else {
                    key = js_NewStringCopyN(cx, chars, length);
                    if (!key)
                        return NULL;
                }
            } else {
                JS_ASSERT(str->isDependent());
                if (!str->undepend(cx))
                    return NULL;
                key = str;
            }

            if (!atoms.relookupOrAdd(p, key, StringToInitialAtomEntry(key))) {
                JS_ReportOutOfMemory(cx); /* SystemAllocPolicy does not report */
                return NULL;
            }
        }
        key->flatSetAtomized();
    }

    AddAtomEntryFlags(*p, flags & (ATOM_PINNED | ATOM_INTERNED));

    JSAtom *atom = STRING_TO_ATOM(key);
    return atom;
}
开发者ID:3l13,项目名称:APE_Server,代码行数:86,代码来源:jsatom.cpp


注:本文中的JSLinearString::flatClearExtensible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。