r=jbetak add additional performance enhancment code by

1. use a 256 bits (8 32bits integer) to prepresent no case block
2. cache the last index
3. use a base variable to remember m*3
This commit is contained in:
ftang%netscape.com 2000-04-05 00:10:14 +00:00
Родитель b31439da94
Коммит 074f4defbb
3 изменённых файлов: 50 добавлений и 268 удалений

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

@ -1,254 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
DO NOT EDIT THIS DOCUMENT !!! THIS DOCUMENT IS GENERATED BY
mozilla/intl/unicharutil/tools/gencasetable.pl
*/
#include "nscore.h"
static PRUnichar gUpperToTitle[] = {
0x01F1, 0x01F2,
0x01C4, 0x01C5,
0x01C7, 0x01C8,
0x01CA, 0x01CB,
};
static PRUint32 gUpperToTitleItems = 4;
static PRUint16 gToUpper[] =
{ /* From To Every Diff */
0x0061, ((0x19 << 8) | 0x01), 0xffe0 ,
0x00b5, ((0x00 << 8) | 0x3b), 0x02e7 ,
0x00e0, ((0x16 << 8) | 0x01), 0xffe0 ,
0x00f8, ((0x06 << 8) | 0x01), 0xffe0 ,
0x00ff, ((0x00 << 8) | 0x01), 0x0079 ,
0x0101, ((0x2e << 8) | 0x02), 0xffff ,
0x0131, ((0x00 << 8) | 0x02), 0xff18 ,
0x0133, ((0x04 << 8) | 0x02), 0xffff ,
0x013a, ((0x0e << 8) | 0x02), 0xffff ,
0x014b, ((0x2c << 8) | 0x02), 0xffff ,
0x017a, ((0x04 << 8) | 0x02), 0xffff ,
0x017f, ((0x00 << 8) | 0x01), 0xfed4 ,
0x0183, ((0x02 << 8) | 0x02), 0xffff ,
0x0188, ((0x04 << 8) | 0x04), 0xffff ,
0x0192, ((0x00 << 8) | 0x06), 0xffff ,
0x0195, ((0x00 << 8) | 0x03), 0x0061 ,
0x0199, ((0x08 << 8) | 0x08), 0xffff ,
0x01a3, ((0x02 << 8) | 0x02), 0xffff ,
0x01a8, ((0x05 << 8) | 0x05), 0xffff ,
0x01b0, ((0x04 << 8) | 0x04), 0xffff ,
0x01b6, ((0x03 << 8) | 0x03), 0xffff ,
0x01bd, ((0x00 << 8) | 0x04), 0xffff ,
0x01bf, ((0x00 << 8) | 0x02), 0x0038 ,
0x01c5, ((0x00 << 8) | 0x06), 0xffff ,
0x01c6, ((0x00 << 8) | 0x01), 0xfffe ,
0x01c8, ((0x00 << 8) | 0x02), 0xffff ,
0x01c9, ((0x00 << 8) | 0x01), 0xfffe ,
0x01cb, ((0x00 << 8) | 0x02), 0xffff ,
0x01cc, ((0x00 << 8) | 0x01), 0xfffe ,
0x01ce, ((0x0e << 8) | 0x02), 0xffff ,
0x01dd, ((0x00 << 8) | 0x01), 0xffb1 ,
0x01df, ((0x10 << 8) | 0x02), 0xffff ,
0x01f2, ((0x00 << 8) | 0x03), 0xffff ,
0x01f3, ((0x00 << 8) | 0x01), 0xfffe ,
0x01f5, ((0x04 << 8) | 0x04), 0xffff ,
0x01fb, ((0x24 << 8) | 0x02), 0xffff ,
0x0223, ((0x10 << 8) | 0x02), 0xffff ,
0x0253, ((0x00 << 8) | 0x20), 0xff2e ,
0x0254, ((0x00 << 8) | 0x01), 0xff32 ,
0x0256, ((0x01 << 8) | 0x01), 0xff33 ,
0x0259, ((0x00 << 8) | 0x02), 0xff36 ,
0x025b, ((0x00 << 8) | 0x02), 0xff35 ,
0x0260, ((0x00 << 8) | 0x05), 0xff33 ,
0x0263, ((0x00 << 8) | 0x03), 0xff31 ,
0x0268, ((0x00 << 8) | 0x05), 0xff2f ,
0x0269, ((0x06 << 8) | 0x06), 0xff2d ,
0x0272, ((0x00 << 8) | 0x03), 0xff2b ,
0x0275, ((0x00 << 8) | 0x03), 0xff2a ,
0x0280, ((0x03 << 8) | 0x03), 0xff26 ,
0x0288, ((0x00 << 8) | 0x05), 0xff26 ,
0x028a, ((0x01 << 8) | 0x01), 0xff27 ,
0x0292, ((0x00 << 8) | 0x07), 0xff25 ,
0x0345, ((0x00 << 8) | 0xb3), 0x0054 ,
0x03ac, ((0x00 << 8) | 0x67), 0xffda ,
0x03ad, ((0x02 << 8) | 0x01), 0xffdb ,
0x03b1, ((0x10 << 8) | 0x01), 0xffe0 ,
0x03c2, ((0x00 << 8) | 0x01), 0xffe1 ,
0x03c3, ((0x08 << 8) | 0x01), 0xffe0 ,
0x03cc, ((0x00 << 8) | 0x01), 0xffc0 ,
0x03cd, ((0x01 << 8) | 0x01), 0xffc1 ,
0x03d0, ((0x00 << 8) | 0x02), 0xffc2 ,
0x03d1, ((0x00 << 8) | 0x01), 0xffc7 ,
0x03d5, ((0x00 << 8) | 0x04), 0xffd1 ,
0x03d6, ((0x00 << 8) | 0x01), 0xffca ,
0x03db, ((0x14 << 8) | 0x02), 0xffff ,
0x03f0, ((0x00 << 8) | 0x01), 0xffaa ,
0x03f1, ((0x00 << 8) | 0x01), 0xffb0 ,
0x03f2, ((0x00 << 8) | 0x01), 0xffb1 ,
0x0430, ((0x1f << 8) | 0x01), 0xffe0 ,
0x0450, ((0x0f << 8) | 0x01), 0xffb0 ,
0x0461, ((0x20 << 8) | 0x02), 0xffff ,
0x048d, ((0x32 << 8) | 0x02), 0xffff ,
0x04c2, ((0x02 << 8) | 0x02), 0xffff ,
0x04c8, ((0x04 << 8) | 0x04), 0xffff ,
0x04d1, ((0x24 << 8) | 0x02), 0xffff ,
0x04f9, ((0x00 << 8) | 0x04), 0xffff ,
0x0561, ((0x25 << 8) | 0x01), 0xffd0 ,
0x1e01, ((0x94 << 8) | 0x02), 0xffff ,
0x1e9b, ((0x00 << 8) | 0x06), 0xffc5 ,
0x1ea1, ((0x58 << 8) | 0x02), 0xffff ,
0x1f00, ((0x07 << 8) | 0x01), 0x0008 ,
0x1f10, ((0x05 << 8) | 0x01), 0x0008 ,
0x1f20, ((0x07 << 8) | 0x01), 0x0008 ,
0x1f30, ((0x07 << 8) | 0x01), 0x0008 ,
0x1f40, ((0x05 << 8) | 0x01), 0x0008 ,
0x1f51, ((0x06 << 8) | 0x02), 0x0008 ,
0x1f60, ((0x07 << 8) | 0x01), 0x0008 ,
0x1f70, ((0x01 << 8) | 0x01), 0x004a ,
0x1f72, ((0x03 << 8) | 0x01), 0x0056 ,
0x1f76, ((0x01 << 8) | 0x01), 0x0064 ,
0x1f78, ((0x01 << 8) | 0x01), 0x0080 ,
0x1f7a, ((0x01 << 8) | 0x01), 0x0070 ,
0x1f7c, ((0x01 << 8) | 0x01), 0x007e ,
0x1f80, ((0x07 << 8) | 0x01), 0x0008 ,
0x1f90, ((0x07 << 8) | 0x01), 0x0008 ,
0x1fa0, ((0x07 << 8) | 0x01), 0x0008 ,
0x1fb0, ((0x01 << 8) | 0x01), 0x0008 ,
0x1fb3, ((0x00 << 8) | 0x02), 0x0009 ,
0x1fbe, ((0x00 << 8) | 0x0b), 0xe3db ,
0x1fc3, ((0x00 << 8) | 0x05), 0x0009 ,
0x1fd0, ((0x01 << 8) | 0x01), 0x0008 ,
0x1fe0, ((0x01 << 8) | 0x01), 0x0008 ,
0x1fe5, ((0x00 << 8) | 0x04), 0x0007 ,
0x1ff3, ((0x00 << 8) | 0x0e), 0x0009 ,
0x2170, ((0x0f << 8) | 0x01), 0xfff0 ,
0x24d0, ((0x19 << 8) | 0x01), 0xffe6 ,
0xff41, ((0x19 << 8) | 0x01), 0xffe0
};
static PRUint32 gToUpperItems = 107;
static PRUint16 gToLower[] =
{ /* From To Every Diff */
0x0041, ((0x19 << 8) | 0x01), 0x0020 ,
0x00c0, ((0x16 << 8) | 0x01), 0x0020 ,
0x00d8, ((0x06 << 8) | 0x01), 0x0020 ,
0x0100, ((0x2e << 8) | 0x02), 0x0001 ,
0x0130, ((0x00 << 8) | 0x00), 0xff39 ,
0x0132, ((0x04 << 8) | 0x02), 0x0001 ,
0x0139, ((0x0e << 8) | 0x02), 0x0001 ,
0x014a, ((0x2c << 8) | 0x02), 0x0001 ,
0x0178, ((0x00 << 8) | 0x00), 0xff87 ,
0x0179, ((0x04 << 8) | 0x02), 0x0001 ,
0x0181, ((0x00 << 8) | 0x00), 0x00d2 ,
0x0182, ((0x02 << 8) | 0x02), 0x0001 ,
0x0186, ((0x00 << 8) | 0x00), 0x00ce ,
0x0187, ((0x00 << 8) | 0x00), 0x0001 ,
0x0189, ((0x01 << 8) | 0x01), 0x00cd ,
0x018b, ((0x00 << 8) | 0x00), 0x0001 ,
0x018e, ((0x00 << 8) | 0x00), 0x004f ,
0x018f, ((0x00 << 8) | 0x00), 0x00ca ,
0x0190, ((0x00 << 8) | 0x00), 0x00cb ,
0x0191, ((0x00 << 8) | 0x00), 0x0001 ,
0x0193, ((0x00 << 8) | 0x00), 0x00cd ,
0x0194, ((0x00 << 8) | 0x00), 0x00cf ,
0x0196, ((0x00 << 8) | 0x00), 0x00d3 ,
0x0197, ((0x00 << 8) | 0x00), 0x00d1 ,
0x0198, ((0x00 << 8) | 0x00), 0x0001 ,
0x019c, ((0x00 << 8) | 0x00), 0x00d3 ,
0x019d, ((0x00 << 8) | 0x00), 0x00d5 ,
0x019f, ((0x00 << 8) | 0x00), 0x00d6 ,
0x01a0, ((0x04 << 8) | 0x02), 0x0001 ,
0x01a6, ((0x00 << 8) | 0x00), 0x00da ,
0x01a7, ((0x00 << 8) | 0x00), 0x0001 ,
0x01a9, ((0x00 << 8) | 0x00), 0x00da ,
0x01ac, ((0x00 << 8) | 0x00), 0x0001 ,
0x01ae, ((0x00 << 8) | 0x00), 0x00da ,
0x01af, ((0x00 << 8) | 0x00), 0x0001 ,
0x01b1, ((0x01 << 8) | 0x01), 0x00d9 ,
0x01b3, ((0x02 << 8) | 0x02), 0x0001 ,
0x01b7, ((0x00 << 8) | 0x00), 0x00db ,
0x01b8, ((0x04 << 8) | 0x04), 0x0001 ,
0x01c4, ((0x00 << 8) | 0x00), 0x0002 ,
0x01c5, ((0x00 << 8) | 0x00), 0x0001 ,
0x01c7, ((0x00 << 8) | 0x00), 0x0002 ,
0x01c8, ((0x00 << 8) | 0x00), 0x0001 ,
0x01ca, ((0x00 << 8) | 0x00), 0x0002 ,
0x01cb, ((0x10 << 8) | 0x02), 0x0001 ,
0x01de, ((0x10 << 8) | 0x02), 0x0001 ,
0x01f1, ((0x00 << 8) | 0x00), 0x0002 ,
0x01f2, ((0x02 << 8) | 0x02), 0x0001 ,
0x01f6, ((0x00 << 8) | 0x00), 0xff9f ,
0x01f7, ((0x00 << 8) | 0x00), 0xffc8 ,
0x01f8, ((0x26 << 8) | 0x02), 0x0001 ,
0x0222, ((0x10 << 8) | 0x02), 0x0001 ,
0x0386, ((0x00 << 8) | 0x00), 0x0026 ,
0x0388, ((0x02 << 8) | 0x01), 0x0025 ,
0x038c, ((0x00 << 8) | 0x00), 0x0040 ,
0x038e, ((0x01 << 8) | 0x01), 0x003f ,
0x0391, ((0x10 << 8) | 0x01), 0x0020 ,
0x03a3, ((0x08 << 8) | 0x01), 0x0020 ,
0x03da, ((0x14 << 8) | 0x02), 0x0001 ,
0x0400, ((0x0f << 8) | 0x01), 0x0050 ,
0x0410, ((0x1f << 8) | 0x01), 0x0020 ,
0x0460, ((0x20 << 8) | 0x02), 0x0001 ,
0x048c, ((0x32 << 8) | 0x02), 0x0001 ,
0x04c1, ((0x02 << 8) | 0x02), 0x0001 ,
0x04c7, ((0x04 << 8) | 0x04), 0x0001 ,
0x04d0, ((0x24 << 8) | 0x02), 0x0001 ,
0x04f8, ((0x00 << 8) | 0x00), 0x0001 ,
0x0531, ((0x25 << 8) | 0x01), 0x0030 ,
0x1e00, ((0x94 << 8) | 0x02), 0x0001 ,
0x1ea0, ((0x58 << 8) | 0x02), 0x0001 ,
0x1f08, ((0x07 << 8) | 0x01), 0xfff8 ,
0x1f18, ((0x05 << 8) | 0x01), 0xfff8 ,
0x1f28, ((0x07 << 8) | 0x01), 0xfff8 ,
0x1f38, ((0x07 << 8) | 0x01), 0xfff8 ,
0x1f48, ((0x05 << 8) | 0x01), 0xfff8 ,
0x1f59, ((0x06 << 8) | 0x02), 0xfff8 ,
0x1f68, ((0x07 << 8) | 0x01), 0xfff8 ,
0x1f88, ((0x07 << 8) | 0x01), 0xfff8 ,
0x1f98, ((0x07 << 8) | 0x01), 0xfff8 ,
0x1fa8, ((0x07 << 8) | 0x01), 0xfff8 ,
0x1fb8, ((0x01 << 8) | 0x01), 0xfff8 ,
0x1fba, ((0x01 << 8) | 0x01), 0xffb6 ,
0x1fbc, ((0x00 << 8) | 0x00), 0xfff7 ,
0x1fc8, ((0x03 << 8) | 0x01), 0xffaa ,
0x1fcc, ((0x00 << 8) | 0x00), 0xfff7 ,
0x1fd8, ((0x01 << 8) | 0x01), 0xfff8 ,
0x1fda, ((0x01 << 8) | 0x01), 0xff9c ,
0x1fe8, ((0x01 << 8) | 0x01), 0xfff8 ,
0x1fea, ((0x01 << 8) | 0x01), 0xff90 ,
0x1fec, ((0x00 << 8) | 0x00), 0xfff9 ,
0x1ff8, ((0x01 << 8) | 0x01), 0xff80 ,
0x1ffa, ((0x01 << 8) | 0x01), 0xff82 ,
0x1ffc, ((0x00 << 8) | 0x00), 0xfff7 ,
0x2126, ((0x00 << 8) | 0x00), 0xe2a3 ,
0x212a, ((0x00 << 8) | 0x00), 0xdf41 ,
0x212b, ((0x00 << 8) | 0x00), 0xdfba ,
0x2160, ((0x0f << 8) | 0x01), 0x0010 ,
0x24b6, ((0x19 << 8) | 0x01), 0x001a ,
0xff21, ((0x19 << 8) | 0x01), 0x0020
};
static PRUint32 gToLowerItems = 99;

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

@ -45,12 +45,7 @@ enum {
#define IS_ASCII_ALPHA(u) (IS_ASCII_UPPER(u) || IS_ASCII_LOWER(u))
#define IS_ASCII_SPACE(u) ( 0x0020 == (u) )
#define IS_NOCASE_CHAR(u) \
(((0x2500 <= (u)) && ( (u) <= 0xFEFF)) || \
((0x0600 <= (u)) && ( (u) <= 0x0FFF)) || \
((0x1100 <= (u)) && ( (u) <= 0x1DFF)) || \
((0x2000 <= (u)) && ( (u) <= 0x20FF)) || \
((0x2200 <= (u)) && ( (u) <= 0x23FF)))
#define IS_NOCASE_CHAR(u) (0==(1&(gCaseBlocks[(u)>>13]>>(0x001F&((u)>>8)))))
// Size of Tables
@ -70,12 +65,14 @@ private:
PRUnichar *mTable;
PRUint32 mSize;
PRUint32 *mCache;
PRUint32 mLastBase;
};
nsCompressedMap::nsCompressedMap(PRUnichar *aTable, PRUint32 aSize)
{
mTable = aTable;
mSize = aSize;
mLastBase = 0;
mCache = new PRUint32[CASE_MAP_CACHE_SIZE];
for(int i = 0; i < CASE_MAP_CACHE_SIZE; i++)
mCache[i] = 0;
@ -98,7 +95,27 @@ PRUnichar nsCompressedMap::Map(PRUnichar aChar)
if(aChar == ((cachedData >> 16) & 0x0000FFFF))
return (cachedData & 0x0000FFFF);
PRUnichar res = this->Lookup(0, (mSize/2), mSize-1, aChar);
// try the last index first
// store into local variable so we can be thread safe
PRUint32 base = mLastBase;
PRUnichar res = 0;
if (( aChar <= ((mTable[base+kSizeEveryIdx] >> 8) +
mTable[base+kLowIdx])) &&
( mTable[base+kLowIdx] <= aChar ))
{
// Hit the last base
if(((mTable[base+kSizeEveryIdx] & 0x00FF) > 0) &&
(0 != ((aChar - mTable[base+kLowIdx]) %
(mTable[base+kSizeEveryIdx] & 0x00FF))))
{
res = aChar;
} else {
res = aChar + mTable[base+kDiffIdx];
}
} else {
res = this->Lookup(0, (mSize/2), mSize-1, aChar);
}
mCache[aChar & CASE_MAP_CACHE_MASK] =
(((aChar << 16) & 0xFFFF0000) | (0x0000FFFF & res));
@ -108,8 +125,9 @@ PRUnichar nsCompressedMap::Map(PRUnichar aChar)
PRUnichar nsCompressedMap::Lookup(
PRUint32 l, PRUint32 m, PRUint32 r, PRUnichar aChar)
{
if ( aChar > ((mTable[(m*3)+kSizeEveryIdx] >> 8) +
mTable[(m*3)+kLowIdx]))
PRUint32 base = m*3;
if ( aChar > ((mTable[base+kSizeEveryIdx] >> 8) +
mTable[base+kLowIdx]))
{
if( l > m )
return aChar;
@ -118,7 +136,7 @@ PRUnichar nsCompressedMap::Lookup(
newm++;
return this->Lookup(m+1, newm , r, aChar);
} else if ( mTable[(m*3)+kLowIdx] > aChar ) {
} else if ( mTable[base+kLowIdx] > aChar ) {
if( r < m )
return aChar;
PRUint32 newm = (l+m-1)/2;
@ -127,13 +145,14 @@ PRUnichar nsCompressedMap::Lookup(
return this->Lookup(l, newm, m-1, aChar);
} else {
if(((mTable[(m*3)+kSizeEveryIdx] & 0x00FF) > 0) &&
(0 != ((aChar - mTable[(m*3)+kLowIdx]) %
(mTable[(m*3)+kSizeEveryIdx] & 0x00FF))))
if(((mTable[base+kSizeEveryIdx] & 0x00FF) > 0) &&
(0 != ((aChar - mTable[base+kLowIdx]) %
(mTable[base+kSizeEveryIdx] & 0x00FF))))
{
return aChar;
}
return aChar + mTable[(m*3)+kDiffIdx];
mLastBase = base; // cache the base
return aChar + mTable[base+kDiffIdx];
}
}

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

@ -173,6 +173,11 @@ while(<UNICODATA>) {
}
$li++;
}
if(( $l ne "") || ($u ne "")) { # if lower or upper case exist
$idx = $cv >> 13;
$bits = 1 << (($cv >> 8) & 0x1F) ;
$blk[$idx] |= $bits;
}
}
@ -329,6 +334,18 @@ for ($i = 0; $i <= $#lcv; $i++)
#
}
print OUT "static PRUint32 gCaseBlocks [8] = {\n";
for($idx=0;$idx<8;$idx++)
{
printf OUT "0x%08X", $blk[$idx];
if($idx != 7) {
printf OUT ",\n";
} else {
printf OUT "\n";
}
}
print OUT "};\n";
######################################################################
#