Bug 412047: optimizing regexp upper/lower. r=crowder,a=blocking1.9

This commit is contained in:
igor%mir2.org 2008-01-16 08:31:15 +00:00
Родитель be237907af
Коммит 22263669d1
1 изменённых файлов: 26 добавлений и 15 удалений

Просмотреть файл

@ -353,22 +353,33 @@ typedef struct REGlobalData {
* code point value is less than decimal 128, then return ch.
* 6. Return cu.
*/
static jschar
upcase(jschar ch)
static uintN
upcase(uintN ch)
{
jschar cu = JS_TOUPPER(ch);
if (ch >= 128 && cu < 128)
uintN cu;
JS_ASSERT((uintN) (jschar) ch == ch);
if (ch < 128) {
if (ch - (uintN) 'a' <= (uintN) ('z' - 'a'))
ch -= (uintN) ('a' - 'A');
return ch;
return cu;
}
cu = JS_TOUPPER(ch);
return (cu < 128) ? ch : cu;
}
static jschar
downcase(jschar ch)
static uintN
downcase(uintN ch)
{
jschar cl = JS_TOLOWER(ch);
if (cl >= 128 && ch < 128)
JS_ASSERT((uintN) (jschar) ch == ch);
if (ch < 128) {
if (ch - (uintN) 'A' <= (uintN) ('Z' - 'A'))
ch += (uintN) ('a' - 'A');
return ch;
return cl;
}
return JS_TOLOWER(ch);
}
/* Construct and initialize an RENode, returning NULL for out-of-memory */
@ -944,7 +955,7 @@ CalculateBitmapSize(CompilerState *state, RENode *target, const jschar *src,
break;
case 'c':
if (src < end && RE_IS_LETTER(*src)) {
localMax = (jschar) (*src++ & 0x1F);
localMax = (uintN) (*src++) & 0x1F;
} else {
--src;
localMax = '\\';
@ -1044,7 +1055,7 @@ lexHex:
break;
}
if (state->flags & JSREG_FOLD) {
c = JS_MAX(upcase((jschar) localMax), downcase((jschar) localMax));
c = (jschar) JS_MAX(upcase(localMax), downcase(localMax));
if (c > localMax)
localMax = c;
}
@ -2220,12 +2231,12 @@ AddCharacterToCharSet(RECharSet *cs, jschar c)
/* Add a character range, c1 to c2 (inclusive) to the RECharSet */
static void
AddCharacterRangeToCharSet(RECharSet *cs, jschar c1, jschar c2)
AddCharacterRangeToCharSet(RECharSet *cs, uintN c1, uintN c2)
{
uintN i;
uintN byteIndex1 = (uintN)(c1 >> 3);
uintN byteIndex2 = (uintN)(c2 >> 3);
uintN byteIndex1 = c1 >> 3;
uintN byteIndex2 = c2 >> 3;
JS_ASSERT((c2 <= cs->length) && (c1 <= c2));