本文整理汇总了C++中JSString::flatChars方法的典型用法代码示例。如果您正苦于以下问题:C++ JSString::flatChars方法的具体用法?C++ JSString::flatChars怎么用?C++ JSString::flatChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSString
的用法示例。
在下文中一共展示了JSString::flatChars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
JSAtom *
js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags)
{
jschar *chars;
JSString str;
JSAtom *atom;
CHECK_REQUEST(cx);
/*
* Avoiding the malloc in js_InflateString on shorter strings saves us
* over 20,000 malloc calls on mozilla browser startup. This compares to
* only 131 calls where the string is longer than a 31 char (net) buffer.
* The vast majority of atomized strings are already in the hashtable. So
* js_AtomizeString rarely has to copy the temp string we make.
*/
#define ATOMIZE_BUF_MAX 32
jschar inflated[ATOMIZE_BUF_MAX];
size_t inflatedLength = ATOMIZE_BUF_MAX - 1;
if (length < ATOMIZE_BUF_MAX) {
js_InflateStringToBuffer(cx, bytes, length, inflated, &inflatedLength);
inflated[inflatedLength] = 0;
chars = inflated;
} else {
inflatedLength = length;
chars = js_InflateString(cx, bytes, &inflatedLength);
if (!chars)
return NULL;
flags |= ATOM_NOCOPY;
}
str.initFlat(chars, inflatedLength);
atom = js_AtomizeString(cx, &str, ATOM_TMPSTR | flags);
if (chars != inflated && str.flatChars())
cx->free(chars);
return atom;
}