landing string defragmentation patch for bug 231995, r/sr=dbaron,jst,dougt

This commit is contained in:
darin@meer.net
2004-02-19 02:44:03 +00:00
parent 6e0f5f8c67
commit 14e471acbc
216 changed files with 12785 additions and 16855 deletions

View File

@@ -489,7 +489,7 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag)
static const nsReadEndCondition theEndCondition(theTerminalsChars);
nsresult result=NS_OK;
PRBool done=PR_FALSE;
nsReadingIterator<PRUnichar> origin, start, end;
nsScannerIterator origin, start, end;
// Start scanning after the first character, because we know it to
// be part of this text token (we wouldn't have come here if it weren't)
@@ -551,7 +551,7 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFlag)
nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScanner& aScanner,
nsString& aEndTagName,PRInt32 aFlag,PRBool& aFlushTokens){
nsresult result=NS_OK;
nsReadingIterator<PRUnichar> theStartOffset, theCurrOffset, theTermStrPos, theStartCommentPos, theAltTermStrPos, endPos;
nsScannerIterator theStartOffset, theCurrOffset, theTermStrPos, theStartCommentPos, theAltTermStrPos, endPos;
PRBool done=PR_FALSE;
PRBool theLastIteration=PR_FALSE;
@@ -578,19 +578,19 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
// will be our last iteration.
const NS_NAMED_LITERAL_STRING(ltslash, "</");
const nsAString& theTerminalString = ltslash + aEndTagName;
const nsString theTerminalString = ltslash + aEndTagName;
PRUint32 termStrLen=theTerminalString.Length();
while((result == NS_OK) && !done) {
PRBool found = PR_FALSE;
nsReadingIterator<PRUnichar> gtOffset,ltOffset = theCurrOffset;
nsScannerIterator gtOffset,ltOffset = theCurrOffset;
while (FindCharInReadable(PRUnichar(kLessThan), ltOffset, endPos) &&
((PRUint32)ltOffset.size_forward() >= termStrLen ||
Distance(ltOffset, endPos) >= termStrLen)) {
// Make a copy of the (presumed) end tag and
// do a case-insensitive comparison
nsReadingIterator<PRUnichar> start(ltOffset), end(ltOffset);
nsScannerIterator start(ltOffset), end(ltOffset);
end.advance(termStrLen);
if (CaseInsensitiveFindInReadable(theTerminalString,start,end) &&
@@ -610,7 +610,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
if (found && theTermStrPos != endPos) {
if(!(aFlag & NS_IPARSER_FLAG_STRICT_MODE) &&
!theLastIteration && !aIgnoreComments) {
nsReadingIterator<PRUnichar> endComment(ltOffset);
nsScannerIterator endComment(ltOffset);
endComment.advance(5);
if ((theStartCommentPos == endPos) &&
@@ -621,7 +621,7 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
if (theStartCommentPos != endPos) {
// Search for --> between <!-- and </TERMINALSTRING>.
theCurrOffset = theStartCommentPos;
nsReadingIterator<PRUnichar> terminal(theTermStrPos);
nsScannerIterator terminal(theTermStrPos);
if (!RFindInReadable(NS_LITERAL_STRING("-->"),
theCurrOffset, terminal)) {
// If you're here it means that we have a bogus terminal string.
@@ -673,15 +673,18 @@ nsresult CTextToken::ConsumeUntil(PRUnichar aChar,PRBool aIgnoreComments,nsScann
void CTextToken::CopyTo(nsAString& aStr)
{
aStr.Assign(mTextValue);
nsScannerIterator start, end;
mTextValue.BeginReading(start);
mTextValue.EndReading(end);
CopyUnicodeTo(start, end, aStr);
}
const nsAString& CTextToken::GetStringValue(void)
{
return mTextValue;
return mTextValue.AsString();
}
void CTextToken::Bind(nsScanner* aScanner, nsReadingIterator<PRUnichar>& aStart, nsReadingIterator<PRUnichar>& aEnd)
void CTextToken::Bind(nsScanner* aScanner, nsScannerIterator& aStart, nsScannerIterator& aEnd)
{
aScanner->BindSubstring(mTextValue, aStart, aEnd);
}
@@ -872,7 +875,7 @@ nsresult CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
PRBool done=PR_FALSE;
PRUnichar quote=0;
nsReadingIterator<PRUnichar> origin, start, end;
nsScannerIterator origin, start, end;
aScanner.CurrentPosition(origin);
start = origin;
@@ -947,7 +950,7 @@ nsresult CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
const nsAString& CMarkupDeclToken::GetStringValue(void)
{
return mTextValue;
return mTextValue.AsString();
}
@@ -974,15 +977,15 @@ CCommentToken::CCommentToken(const nsAString& aName) : CHTMLToken(eHTMLTag_comme
}
void CCommentToken::AppendSourceTo(nsAString& anOutputString){
anOutputString.Append(mCommentDecl);
AppendUnicodeTo(mCommentDecl, anOutputString);
}
static PRBool IsCommentEnd(
const nsReadingIterator<PRUnichar>& aCurrent,
const nsReadingIterator<PRUnichar>& aEnd,
nsReadingIterator<PRUnichar>& aGt)
const nsScannerIterator& aCurrent,
const nsScannerIterator& aEnd,
nsScannerIterator& aGt)
{
nsReadingIterator<PRUnichar> current = aCurrent;
nsScannerIterator current = aCurrent;
PRInt32 dashes = 0;
while ((current != aEnd) && (dashes != 2)) {
@@ -1009,11 +1012,11 @@ nsresult CCommentToken::ConsumeStrictComment(nsScanner& aScanner)
when they're formatted per spec, but if they're not
we don't handle them well.
*********************************************************/
nsReadingIterator<PRUnichar> end, current, gt, lt;
nsScannerIterator end, current, gt, lt;
aScanner.EndReading(end);
aScanner.CurrentPosition(current);
nsReadingIterator<PRUnichar> beginData = end;
nsScannerIterator beginData = end;
lt = current;
lt.advance(-2); // <!
@@ -1022,7 +1025,7 @@ nsresult CCommentToken::ConsumeStrictComment(nsScanner& aScanner)
if (current != end && *current == kMinus &&
++current != end && *current == kMinus &&
++current != end) {
nsReadingIterator<PRUnichar> currentEnd = end;
nsScannerIterator currentEnd = end;
PRBool balancedComment = PR_FALSE;
static NS_NAMED_LITERAL_STRING(dashes,"--");
beginData = current;
@@ -1087,13 +1090,13 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
commonly used, but it doesn't really consume them
per spec (But then, neither does IE or Nav).
*********************************************************/
nsReadingIterator<PRUnichar> end, current;
nsScannerIterator end, current;
aScanner.EndReading(end);
aScanner.CurrentPosition(current);
nsReadingIterator<PRUnichar> beginData = current,
beginLastMinus = end,
bestAltCommentEnd = end,
lt = current;
nsScannerIterator beginData = current,
beginLastMinus = end,
bestAltCommentEnd = end,
lt = current;
lt.advance(-2); // <!
// When we get here, we have always already consumed <!
@@ -1108,7 +1111,7 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
++beginData;
// Long form comment
nsReadingIterator<PRUnichar> currentEnd = end, gt = end;
nsScannerIterator currentEnd = end, gt = end;
// Find the end of the comment
while (FindCharInReadable(kGreaterThan, current, currentEnd)) {
@@ -1184,7 +1187,7 @@ nsresult CCommentToken::ConsumeQuirksComment(nsScanner& aScanner)
// Find the end of the comment
current = beginData;
if (FindCharInReadable(kGreaterThan, current, end)) {
nsReadingIterator<PRUnichar> gt = current;
nsScannerIterator gt = current;
if (current != beginData) {
--current;
if (current != beginData && *current == kMinus) { // ->
@@ -1243,7 +1246,7 @@ nsresult CCommentToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 aFl
const nsAString& CCommentToken::GetStringValue(void)
{
return mComment;
return mComment.AsString();
}
/*
@@ -1302,10 +1305,10 @@ PRInt32 CNewlineToken::GetTokenType(void) {
}
static nsSlidingSubstring* gNewlineStr;
static nsScannerSubstring* gNewlineStr;
void CNewlineToken::AllocNewline()
{
gNewlineStr = new nsSlidingSubstring(NS_LITERAL_STRING("\n"));
gNewlineStr = new nsScannerSubstring(NS_LITERAL_STRING("\n"));
}
void CNewlineToken::FreeNewline()
@@ -1323,7 +1326,7 @@ void CNewlineToken::FreeNewline()
* @return nsString reference to internal string value
*/
const nsAString& CNewlineToken::GetStringValue(void) {
return *gNewlineStr;
return gNewlineStr->AsString();
}
/*
@@ -1449,7 +1452,7 @@ PRInt32 CAttributeToken::GetTokenType(void) {
void CAttributeToken::SanitizeKey() {
PRInt32 length=mTextKey.Length();
if(length > 0) {
nsReadingIterator<PRUnichar> iter, begin, end;
nsScannerIterator iter, begin, end;
mTextKey.BeginReading(begin);
mTextKey.EndReading(end);
iter = end;
@@ -1465,15 +1468,20 @@ void CAttributeToken::SanitizeKey() {
// If there were any illegal characters, just copy out the
// legal part
if (iter != --end) {
nsAutoString str;
CopyUnicodeTo(begin, ++iter, str);
mTextKey.Rebind(str);
nsAutoString buf;
CopyUnicodeTo(begin, ++iter, buf);
mTextKey.Rebind(buf);
}
}
return;
}
const nsAString& CAttributeToken::GetKey(void)
{
return mTextKey.AsString();
}
const nsAString& CAttributeToken::GetStringValue(void)
{
return mTextValue;
@@ -1499,7 +1507,7 @@ void CAttributeToken::GetSource(nsString& anOutputString){
* @return nada
*/
void CAttributeToken::AppendSourceTo(nsAString& anOutputString){
anOutputString.Append(mTextKey);
AppendUnicodeTo(mTextKey, anOutputString);
if(mTextValue.Length() || mHasEqualWithoutValue)
anOutputString.Append(NS_LITERAL_STRING("="));
anOutputString.Append(mTextValue);
@@ -1643,7 +1651,7 @@ nsresult ConsumeQuotedString(PRUnichar aChar,
terminateCondition = &theTerminateConditionApostrophe;
nsresult result=NS_OK;
nsReadingIterator<PRUnichar> theOffset;
nsScannerIterator theOffset;
aScanner.CurrentPosition(theOffset);
result=ConsumeAttributeValueText(aString,aScanner,*terminateCondition,aFlag);
@@ -1682,7 +1690,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a
//I changed a bit of this method to use aRetain so that we do the right
//thing in viewsource. The ws/cr/lf sequences are now maintained, and viewsource looks good.
nsReadingIterator<PRUnichar> wsstart, wsend;
nsScannerIterator wsstart, wsend;
if (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE) {
result = aScanner.ReadWhitespace(wsstart, wsend, mNewlineCount);
@@ -1700,7 +1708,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a
PRUnichar('\b'), PRUnichar(0) };
static const nsReadEndCondition theEndCondition(theTerminalsChars);
nsReadingIterator<PRUnichar> start, end;
nsScannerIterator start, end;
result=aScanner.ReadUntil(start,end,theEndCondition,PR_FALSE);
if (!(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
@@ -1805,8 +1813,8 @@ void CAttributeToken::SetKey(const nsAString& aKey)
}
void CAttributeToken::BindKey(nsScanner* aScanner,
nsReadingIterator<PRUnichar>& aStart,
nsReadingIterator<PRUnichar>& aEnd)
nsScannerIterator& aStart,
nsScannerIterator& aEnd)
{
aScanner->BindSubstring(mTextKey, aStart, aEnd);
}
@@ -2409,7 +2417,7 @@ nsresult CDoctypeDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
};
static const nsReadEndCondition theEndCondition(terminalChars);
nsReadingIterator<PRUnichar> start, end;
nsScannerIterator start, end;
aScanner.CurrentPosition(start);
aScanner.EndReading(end);