From 3ffdadab9b9e0b5958e58ec835096dc95fbb72d0 Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Sat, 29 Aug 2009 02:17:10 -0700 Subject: [PATCH] Fast path for is/is not space character classification (513379, r=sayrer). --- js/src/jsstr.cpp | 9 --------- js/src/jsstr.h | 24 +++++++++++++++++++----- js/src/jsstrinlines.h | 8 ++++++-- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index 86e5b6d89b3..25fff3bc82e 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -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) { diff --git a/js/src/jsstr.h b/js/src/jsstr.h index 72745b9711e..c5554955b59 100644 --- a/js/src/jsstr.h +++ b/js/src/jsstr.h @@ -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 diff --git a/js/src/jsstrinlines.h b/js/src/jsstrinlines.h index 9185b045c69..6b859553666 100644 --- a/js/src/jsstrinlines.h +++ b/js/src/jsstrinlines.h @@ -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)