From 54ab7cf886b9a260f1b5a3d36e458a42621bfe48 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Mon, 19 Jul 1999 03:09:16 +0000 Subject: [PATCH] switching to faster string APIs --- htmlparser/src/nsHTMLTokens.cpp | 2 +- htmlparser/src/nsParser.cpp | 2 +- htmlparser/src/nsScanner.cpp | 27 +++++++++++++++++--------- htmlparser/src/nsXIFDTD.cpp | 2 +- parser/htmlparser/src/nsHTMLTokens.cpp | 2 +- parser/htmlparser/src/nsParser.cpp | 2 +- parser/htmlparser/src/nsScanner.cpp | 27 +++++++++++++++++--------- parser/htmlparser/src/nsXIFDTD.cpp | 2 +- 8 files changed, 42 insertions(+), 24 deletions(-) diff --git a/htmlparser/src/nsHTMLTokens.cpp b/htmlparser/src/nsHTMLTokens.cpp index 25682e2510f..dade8e8b606 100644 --- a/htmlparser/src/nsHTMLTokens.cpp +++ b/htmlparser/src/nsHTMLTokens.cpp @@ -558,7 +558,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann result=aScanner.ReadUntil(temp,theTerminals,PR_TRUE,PR_FALSE); } 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' - PRInt32 theSubIndex=theBufCopy.Find(kGreaterThan,theIndex+1); + PRInt32 theSubIndex=theBufCopy.FindChar(kGreaterThan,theIndex+1); theBufCopy.Truncate(theSubIndex); theSubIndex=theBufCopy.Find("HTML 4.0"); if(kNotFoundLength(aBuffer, 0, aLen, &unicharBufLen); - PRUnichar *unichars = new PRUnichar [ unicharBufLen ]; + mBuffer.SetCapacity(mBuffer.mLength+unicharBufLen); + PRUnichar *unichars = (PRUnichar*)mBuffer.GetUnicode(); + unichars+=mBuffer.mLength; nsresult res; do { - PRInt32 srcLength = aLen; + PRInt32 srcLength = aLen; PRInt32 unicharLength = unicharBufLen; 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; // if we failed, we consume one byte by replace it with U+FFFD // and try conversion again. @@ -273,7 +282,7 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ // we continue convert the bytes data into Unicode // if we have conversion error and we have more data. - delete[] unichars; + //delete[] unichars; } else { mBuffer.Append(aBuffer,aLen); @@ -459,7 +468,7 @@ nsresult nsScanner::SkipOver(nsString& aSkipSet){ while(NS_OK==result) { result=GetChar(theChar); if(NS_OK == result) { - PRInt32 pos=aSkipSet.Find(theChar); + PRInt32 pos=aSkipSet.FindChar(theChar); if(kNotFound==pos) { PutBack(theChar); break; @@ -486,7 +495,7 @@ nsresult nsScanner::SkipTo(nsString& aValidSet){ while(NS_OK==result) { result=GetChar(ch); if(NS_OK == result) { - PRInt32 pos=aValidSet.Find(ch); + PRInt32 pos=aValidSet.FindChar(ch); if(kNotFound!=pos) { PutBack(ch); break; @@ -535,7 +544,7 @@ nsresult nsScanner::ReadWhile(nsString& aString, while(NS_OK==result) { result=GetChar(theChar); 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(addTerminal) aString+=theChar; @@ -571,7 +580,7 @@ nsresult nsScanner::ReadUntil(nsString& aString, while(NS_OK == result) { result=GetChar(theChar); 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(addTerminal) aString+=theChar; diff --git a/htmlparser/src/nsXIFDTD.cpp b/htmlparser/src/nsXIFDTD.cpp index 19d220d43a3..b217ce63b2d 100644 --- a/htmlparser/src/nsXIFDTD.cpp +++ b/htmlparser/src/nsXIFDTD.cpp @@ -1787,7 +1787,7 @@ void nsXIFDTD::AddCSSSelector(const nsIParserNode& aNode) void nsXIFDTD::BeginCSSDeclarationList(const nsIParserNode& aNode) { - PRInt32 indx = mBuffer.RFind('\n'); + PRInt32 indx = mBuffer.RFindChar('\n'); if (indx == kNotFound) indx = 0; PRInt32 offset = mBuffer.Length() - indx; diff --git a/parser/htmlparser/src/nsHTMLTokens.cpp b/parser/htmlparser/src/nsHTMLTokens.cpp index 25682e2510f..dade8e8b606 100644 --- a/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/parser/htmlparser/src/nsHTMLTokens.cpp @@ -558,7 +558,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann result=aScanner.ReadUntil(temp,theTerminals,PR_TRUE,PR_FALSE); } 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' - PRInt32 theSubIndex=theBufCopy.Find(kGreaterThan,theIndex+1); + PRInt32 theSubIndex=theBufCopy.FindChar(kGreaterThan,theIndex+1); theBufCopy.Truncate(theSubIndex); theSubIndex=theBufCopy.Find("HTML 4.0"); if(kNotFoundLength(aBuffer, 0, aLen, &unicharBufLen); - PRUnichar *unichars = new PRUnichar [ unicharBufLen ]; + mBuffer.SetCapacity(mBuffer.mLength+unicharBufLen); + PRUnichar *unichars = (PRUnichar*)mBuffer.GetUnicode(); + unichars+=mBuffer.mLength; nsresult res; do { - PRInt32 srcLength = aLen; + PRInt32 srcLength = aLen; PRInt32 unicharLength = unicharBufLen; 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; // if we failed, we consume one byte by replace it with U+FFFD // and try conversion again. @@ -273,7 +282,7 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ // we continue convert the bytes data into Unicode // if we have conversion error and we have more data. - delete[] unichars; + //delete[] unichars; } else { mBuffer.Append(aBuffer,aLen); @@ -459,7 +468,7 @@ nsresult nsScanner::SkipOver(nsString& aSkipSet){ while(NS_OK==result) { result=GetChar(theChar); if(NS_OK == result) { - PRInt32 pos=aSkipSet.Find(theChar); + PRInt32 pos=aSkipSet.FindChar(theChar); if(kNotFound==pos) { PutBack(theChar); break; @@ -486,7 +495,7 @@ nsresult nsScanner::SkipTo(nsString& aValidSet){ while(NS_OK==result) { result=GetChar(ch); if(NS_OK == result) { - PRInt32 pos=aValidSet.Find(ch); + PRInt32 pos=aValidSet.FindChar(ch); if(kNotFound!=pos) { PutBack(ch); break; @@ -535,7 +544,7 @@ nsresult nsScanner::ReadWhile(nsString& aString, while(NS_OK==result) { result=GetChar(theChar); 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(addTerminal) aString+=theChar; @@ -571,7 +580,7 @@ nsresult nsScanner::ReadUntil(nsString& aString, while(NS_OK == result) { result=GetChar(theChar); 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(addTerminal) aString+=theChar; diff --git a/parser/htmlparser/src/nsXIFDTD.cpp b/parser/htmlparser/src/nsXIFDTD.cpp index 19d220d43a3..b217ce63b2d 100644 --- a/parser/htmlparser/src/nsXIFDTD.cpp +++ b/parser/htmlparser/src/nsXIFDTD.cpp @@ -1787,7 +1787,7 @@ void nsXIFDTD::AddCSSSelector(const nsIParserNode& aNode) void nsXIFDTD::BeginCSSDeclarationList(const nsIParserNode& aNode) { - PRInt32 indx = mBuffer.RFind('\n'); + PRInt32 indx = mBuffer.RFindChar('\n'); if (indx == kNotFound) indx = 0; PRInt32 offset = mBuffer.Length() - indx;