switching to faster string APIs

This commit is contained in:
rickg%netscape.com 1999-07-19 03:09:16 +00:00
Родитель 597d6041d4
Коммит 54ab7cf886
8 изменённых файлов: 42 добавлений и 24 удалений

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

@ -558,7 +558,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
result=aScanner.ReadUntil(temp,theTerminals,PR_TRUE,PR_FALSE); result=aScanner.ReadUntil(temp,theTerminals,PR_TRUE,PR_FALSE);
} }
temp.Right(theRight,termStrLen+10); //first, get a wad of chars from the temp string temp.Right(theRight,termStrLen+10); //first, get a wad of chars from the temp string
rpos=theRight.RFind('<'); //now scan for the '<' rpos=theRight.RFindChar('<'); //now scan for the '<'
if(-1<rpos) if(-1<rpos)
rpos=theRight.RFind(aTerminalString,PR_TRUE); rpos=theRight.RFind(aTerminalString,PR_TRUE);
done=PRBool(-1<rpos); done=PRBool(-1<rpos);

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

@ -452,7 +452,7 @@ eParseMode DetermineParseMode(nsParser& aParser) {
if(kNotFound<theIndex) { if(kNotFound<theIndex) {
//good, we found "DOCTYPE" -- now go find it's end delimiter '>' //good, we found "DOCTYPE" -- now go find it's end delimiter '>'
PRInt32 theSubIndex=theBufCopy.Find(kGreaterThan,theIndex+1); PRInt32 theSubIndex=theBufCopy.FindChar(kGreaterThan,theIndex+1);
theBufCopy.Truncate(theSubIndex); theBufCopy.Truncate(theSubIndex);
theSubIndex=theBufCopy.Find("HTML 4.0"); theSubIndex=theBufCopy.Find("HTML 4.0");
if(kNotFound<theSubIndex) { if(kNotFound<theSubIndex) {

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

@ -243,18 +243,27 @@ PRBool nsScanner::Append(nsString& aBuffer) {
*/ */
PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
/*************************** SUBTLETY ALERT!! ************************
The following block of code converts aBuffer into unicode.
The subtlty is that we do it "in-place" on the underlying mBuffer.
This is so that we can avoid unnecessary copying of buffer data.
*********************************************************************/
if(mUnicodeDecoder) { if(mUnicodeDecoder) {
PRInt32 unicharBufLen = 0; PRInt32 unicharBufLen = 0;
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen); mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen);
PRUnichar *unichars = new PRUnichar [ unicharBufLen ]; mBuffer.SetCapacity(mBuffer.mLength+unicharBufLen);
PRUnichar *unichars = (PRUnichar*)mBuffer.GetUnicode();
unichars+=mBuffer.mLength;
nsresult res; nsresult res;
do { do {
PRInt32 srcLength = aLen; PRInt32 srcLength = aLen;
PRInt32 unicharLength = unicharBufLen; PRInt32 unicharLength = unicharBufLen;
res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength ); res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
unichars[unicharLength]=0; //add this since the unicode converters can't be trusted to do so. unichars[mBuffer.mLength+unicharLength]=0; //add this since the unicode converters can't be trusted to do so.
mBuffer.mLength+=unicharLength;
// mBuffer.Append(unichars, unicharLength);
mBuffer.Append(unichars, unicharLength);
mTotalRead += unicharLength; mTotalRead += unicharLength;
// if we failed, we consume one byte by replace it with U+FFFD // if we failed, we consume one byte by replace it with U+FFFD
// and try conversion again. // and try conversion again.
@ -273,7 +282,7 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
// we continue convert the bytes data into Unicode // we continue convert the bytes data into Unicode
// if we have conversion error and we have more data. // if we have conversion error and we have more data.
delete[] unichars; //delete[] unichars;
} }
else { else {
mBuffer.Append(aBuffer,aLen); mBuffer.Append(aBuffer,aLen);
@ -459,7 +468,7 @@ nsresult nsScanner::SkipOver(nsString& aSkipSet){
while(NS_OK==result) { while(NS_OK==result) {
result=GetChar(theChar); result=GetChar(theChar);
if(NS_OK == result) { if(NS_OK == result) {
PRInt32 pos=aSkipSet.Find(theChar); PRInt32 pos=aSkipSet.FindChar(theChar);
if(kNotFound==pos) { if(kNotFound==pos) {
PutBack(theChar); PutBack(theChar);
break; break;
@ -486,7 +495,7 @@ nsresult nsScanner::SkipTo(nsString& aValidSet){
while(NS_OK==result) { while(NS_OK==result) {
result=GetChar(ch); result=GetChar(ch);
if(NS_OK == result) { if(NS_OK == result) {
PRInt32 pos=aValidSet.Find(ch); PRInt32 pos=aValidSet.FindChar(ch);
if(kNotFound!=pos) { if(kNotFound!=pos) {
PutBack(ch); PutBack(ch);
break; break;
@ -535,7 +544,7 @@ nsresult nsScanner::ReadWhile(nsString& aString,
while(NS_OK==result) { while(NS_OK==result) {
result=GetChar(theChar); result=GetChar(theChar);
if(NS_OK==result) { if(NS_OK==result) {
PRInt32 pos=(anOrderedSet) ? aValidSet.BinarySearch(theChar) : aValidSet.Find(theChar); PRInt32 pos=(anOrderedSet) ? aValidSet.BinarySearch(theChar) : aValidSet.FindChar(theChar);
if(kNotFound==pos) { if(kNotFound==pos) {
if(addTerminal) if(addTerminal)
aString+=theChar; aString+=theChar;
@ -571,7 +580,7 @@ nsresult nsScanner::ReadUntil(nsString& aString,
while(NS_OK == result) { while(NS_OK == result) {
result=GetChar(theChar); result=GetChar(theChar);
if(NS_OK==result) { if(NS_OK==result) {
PRInt32 pos=(anOrderedSet) ? aTerminalSet.BinarySearch(theChar) : aTerminalSet.Find(theChar); PRInt32 pos=(anOrderedSet) ? aTerminalSet.BinarySearch(theChar) : aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) { if(kNotFound!=pos) {
if(addTerminal) if(addTerminal)
aString+=theChar; aString+=theChar;

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

@ -1787,7 +1787,7 @@ void nsXIFDTD::AddCSSSelector(const nsIParserNode& aNode)
void nsXIFDTD::BeginCSSDeclarationList(const nsIParserNode& aNode) void nsXIFDTD::BeginCSSDeclarationList(const nsIParserNode& aNode)
{ {
PRInt32 indx = mBuffer.RFind('\n'); PRInt32 indx = mBuffer.RFindChar('\n');
if (indx == kNotFound) if (indx == kNotFound)
indx = 0; indx = 0;
PRInt32 offset = mBuffer.Length() - indx; PRInt32 offset = mBuffer.Length() - indx;

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

@ -558,7 +558,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
result=aScanner.ReadUntil(temp,theTerminals,PR_TRUE,PR_FALSE); result=aScanner.ReadUntil(temp,theTerminals,PR_TRUE,PR_FALSE);
} }
temp.Right(theRight,termStrLen+10); //first, get a wad of chars from the temp string temp.Right(theRight,termStrLen+10); //first, get a wad of chars from the temp string
rpos=theRight.RFind('<'); //now scan for the '<' rpos=theRight.RFindChar('<'); //now scan for the '<'
if(-1<rpos) if(-1<rpos)
rpos=theRight.RFind(aTerminalString,PR_TRUE); rpos=theRight.RFind(aTerminalString,PR_TRUE);
done=PRBool(-1<rpos); done=PRBool(-1<rpos);

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

@ -452,7 +452,7 @@ eParseMode DetermineParseMode(nsParser& aParser) {
if(kNotFound<theIndex) { if(kNotFound<theIndex) {
//good, we found "DOCTYPE" -- now go find it's end delimiter '>' //good, we found "DOCTYPE" -- now go find it's end delimiter '>'
PRInt32 theSubIndex=theBufCopy.Find(kGreaterThan,theIndex+1); PRInt32 theSubIndex=theBufCopy.FindChar(kGreaterThan,theIndex+1);
theBufCopy.Truncate(theSubIndex); theBufCopy.Truncate(theSubIndex);
theSubIndex=theBufCopy.Find("HTML 4.0"); theSubIndex=theBufCopy.Find("HTML 4.0");
if(kNotFound<theSubIndex) { if(kNotFound<theSubIndex) {

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

@ -243,18 +243,27 @@ PRBool nsScanner::Append(nsString& aBuffer) {
*/ */
PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
/*************************** SUBTLETY ALERT!! ************************
The following block of code converts aBuffer into unicode.
The subtlty is that we do it "in-place" on the underlying mBuffer.
This is so that we can avoid unnecessary copying of buffer data.
*********************************************************************/
if(mUnicodeDecoder) { if(mUnicodeDecoder) {
PRInt32 unicharBufLen = 0; PRInt32 unicharBufLen = 0;
mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen); mUnicodeDecoder->Length(aBuffer, 0, aLen, &unicharBufLen);
PRUnichar *unichars = new PRUnichar [ unicharBufLen ]; mBuffer.SetCapacity(mBuffer.mLength+unicharBufLen);
PRUnichar *unichars = (PRUnichar*)mBuffer.GetUnicode();
unichars+=mBuffer.mLength;
nsresult res; nsresult res;
do { do {
PRInt32 srcLength = aLen; PRInt32 srcLength = aLen;
PRInt32 unicharLength = unicharBufLen; PRInt32 unicharLength = unicharBufLen;
res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength ); res = mUnicodeDecoder->Convert(unichars, 0, &unicharLength,aBuffer, 0, &srcLength );
unichars[unicharLength]=0; //add this since the unicode converters can't be trusted to do so. unichars[mBuffer.mLength+unicharLength]=0; //add this since the unicode converters can't be trusted to do so.
mBuffer.mLength+=unicharLength;
// mBuffer.Append(unichars, unicharLength);
mBuffer.Append(unichars, unicharLength);
mTotalRead += unicharLength; mTotalRead += unicharLength;
// if we failed, we consume one byte by replace it with U+FFFD // if we failed, we consume one byte by replace it with U+FFFD
// and try conversion again. // and try conversion again.
@ -273,7 +282,7 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){
// we continue convert the bytes data into Unicode // we continue convert the bytes data into Unicode
// if we have conversion error and we have more data. // if we have conversion error and we have more data.
delete[] unichars; //delete[] unichars;
} }
else { else {
mBuffer.Append(aBuffer,aLen); mBuffer.Append(aBuffer,aLen);
@ -459,7 +468,7 @@ nsresult nsScanner::SkipOver(nsString& aSkipSet){
while(NS_OK==result) { while(NS_OK==result) {
result=GetChar(theChar); result=GetChar(theChar);
if(NS_OK == result) { if(NS_OK == result) {
PRInt32 pos=aSkipSet.Find(theChar); PRInt32 pos=aSkipSet.FindChar(theChar);
if(kNotFound==pos) { if(kNotFound==pos) {
PutBack(theChar); PutBack(theChar);
break; break;
@ -486,7 +495,7 @@ nsresult nsScanner::SkipTo(nsString& aValidSet){
while(NS_OK==result) { while(NS_OK==result) {
result=GetChar(ch); result=GetChar(ch);
if(NS_OK == result) { if(NS_OK == result) {
PRInt32 pos=aValidSet.Find(ch); PRInt32 pos=aValidSet.FindChar(ch);
if(kNotFound!=pos) { if(kNotFound!=pos) {
PutBack(ch); PutBack(ch);
break; break;
@ -535,7 +544,7 @@ nsresult nsScanner::ReadWhile(nsString& aString,
while(NS_OK==result) { while(NS_OK==result) {
result=GetChar(theChar); result=GetChar(theChar);
if(NS_OK==result) { if(NS_OK==result) {
PRInt32 pos=(anOrderedSet) ? aValidSet.BinarySearch(theChar) : aValidSet.Find(theChar); PRInt32 pos=(anOrderedSet) ? aValidSet.BinarySearch(theChar) : aValidSet.FindChar(theChar);
if(kNotFound==pos) { if(kNotFound==pos) {
if(addTerminal) if(addTerminal)
aString+=theChar; aString+=theChar;
@ -571,7 +580,7 @@ nsresult nsScanner::ReadUntil(nsString& aString,
while(NS_OK == result) { while(NS_OK == result) {
result=GetChar(theChar); result=GetChar(theChar);
if(NS_OK==result) { if(NS_OK==result) {
PRInt32 pos=(anOrderedSet) ? aTerminalSet.BinarySearch(theChar) : aTerminalSet.Find(theChar); PRInt32 pos=(anOrderedSet) ? aTerminalSet.BinarySearch(theChar) : aTerminalSet.FindChar(theChar);
if(kNotFound!=pos) { if(kNotFound!=pos) {
if(addTerminal) if(addTerminal)
aString+=theChar; aString+=theChar;

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

@ -1787,7 +1787,7 @@ void nsXIFDTD::AddCSSSelector(const nsIParserNode& aNode)
void nsXIFDTD::BeginCSSDeclarationList(const nsIParserNode& aNode) void nsXIFDTD::BeginCSSDeclarationList(const nsIParserNode& aNode)
{ {
PRInt32 indx = mBuffer.RFind('\n'); PRInt32 indx = mBuffer.RFindChar('\n');
if (indx == kNotFound) if (indx == kNotFound)
indx = 0; indx = 0;
PRInt32 offset = mBuffer.Length() - indx; PRInt32 offset = mBuffer.Length() - indx;