Fast path for is/is not space character classification (513379, r=sayrer).

This commit is contained in:
Andreas Gal 2009-08-29 02:17:10 -07:00
parent 7d3f588878
commit 3ffdadab9b
3 changed files with 25 additions and 16 deletions

View File

@ -3081,15 +3081,6 @@ js_strchr_limit(const jschar *s, jschar c, const jschar *limit)
return NULL;
}
const jschar *
js_SkipWhiteSpace(const jschar *s, const jschar *end)
{
JS_ASSERT(s <= end);
while (s != end && JS_ISSPACE(*s))
s++;
return s;
}
jschar *
js_InflateString(JSContext *cx, const char *bytes, size_t *lengthp)
{

View File

@ -519,9 +519,17 @@ extern const bool js_alnum[];
#define JS_ISDIGIT(c) (JS_CTYPE(c) == JSCT_DECIMAL_DIGIT_NUMBER)
/* XXXbe unify on A/X/Y tbls, avoid ctype.h? */
/* XXXbe fs, etc. ? */
#define JS_ISSPACE(c) ((JS_CCODE(c) & 0x00070000) == 0x00040000)
static inline bool
JS_ISSPACE(jschar c)
{
uint32 w = uint32(c);
if (w < 256) {
return w <= ' ' && (w == ' ' || (9 <= w && w <= 0xD));
} else {
return (JS_CCODE(w) & 0x00070000) == 0x00040000;
}
}
#define JS_ISPRINT(c) ((c) < 128 && isprint(c))
#define JS_ISUPPER(c) (JS_CTYPE(c) == JSCT_UPPERCASE_LETTER)
@ -686,8 +694,14 @@ js_strchr_limit(const jschar *s, jschar c, const jschar *limit);
/*
* Return s advanced past any Unicode white space characters.
*/
extern const jschar *
js_SkipWhiteSpace(const jschar *s, const jschar *end);
static inline const jschar *
js_SkipWhiteSpace(const jschar *s, const jschar *end)
{
JS_ASSERT(s <= end);
while (s != end && JS_ISSPACE(*s))
s++;
return s;
}
/*
* Inflate bytes to JS chars and vice versa. Report out of memory via cx

View File

@ -44,7 +44,9 @@
JS_BEGIN_EXTERN_C
inline JSString *JSString::getUnitString(JSContext *cx, jschar c) {
inline JSString *
JSString::getUnitString(JSContext *cx, jschar c)
{
JS_ASSERT(c < UNIT_STRING_LIMIT);
JSRuntime *rt = cx->runtime;
JSString **unitStrings = rt->unitStrings;
@ -54,7 +56,9 @@ inline JSString *JSString::getUnitString(JSContext *cx, jschar c) {
return js_MakeUnitString(cx, c);
}
inline JSString *JSString::getUnitString(JSContext *cx, JSString *str, size_t index) {
inline JSString *
JSString::getUnitString(JSContext *cx, JSString *str, size_t index)
{
JS_ASSERT(index < str->length());
jschar c = str->chars()[index];
if (c >= UNIT_STRING_LIMIT)