Checking in jeff.qiu@sun.com's fix for bug 77585. Speeding up nsGenericDOMDataNode::AppendData(). r=cbiesinger@web.de, sr=jst@netscape.com

This commit is contained in:
jst%netscape.com 2002-04-10 21:44:04 +00:00
Родитель ffcb697f87
Коммит cddc2e1391
4 изменённых файлов: 39 добавлений и 5 удалений

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

@ -500,12 +500,22 @@ nsGenericDOMDataNode::AppendData(const nsAString& aData)
{ {
#if 1 #if 1
nsresult rv = NS_OK; nsresult rv = NS_OK;
PRInt32 length = 0;
nsAutoString old_data; // See bugzilla bug 77585.
if (mText.Is2b() || (!IsASCII(aData))) {
nsAutoString old_data;
mText.AppendTo(old_data);
length = old_data.Length();
rv = SetText(old_data + aData, PR_FALSE);
} else {
nsCAutoString old_data;
mText.AppendTo(old_data);
length = old_data.Length();
old_data.AppendWithConversion(aData);
rv = SetText(old_data.get(), old_data.Length(), PR_FALSE);
}
mText.AppendTo(old_data);
rv = SetText(old_data + aData, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Trigger a reflow // Trigger a reflow
@ -516,7 +526,7 @@ nsGenericDOMDataNode::AppendData(const nsAString& aData)
nsTextContentChangeData* tccd = nsnull; nsTextContentChangeData* tccd = nsnull;
rv = NS_NewTextContentChangeData(&tccd); rv = NS_NewTextContentChangeData(&tccd);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
tccd->SetData(nsITextContentChangeData::Append, old_data.Length(), tccd->SetData(nsITextContentChangeData::Append, length,
aData.Length()); aData.Length());
rv = mDocument->ContentChanged(this, tccd); rv = mDocument->ContentChanged(this, tccd);
NS_RELEASE(tccd); NS_RELEASE(tccd);

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

@ -40,6 +40,7 @@
#include "nsAString.h" #include "nsAString.h"
class nsString; class nsString;
class nsCString;
// XXX should this normalize the code to keep a \u0000 at the end? // XXX should this normalize the code to keep a \u0000 at the end?
@ -205,6 +206,11 @@ public:
*/ */
void AppendTo(nsString& aString) const; void AppendTo(nsString& aString) const;
/**
* Append the contents of this string fragment to aCString
*/
void AppendTo(nsCString& aCString) const;
/** /**
* Make a copy of the fragments contents starting at offset for * Make a copy of the fragments contents starting at offset for
* count characters. The offset and count will be adjusted to * count characters. The offset and count will be adjusted to

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

@ -40,6 +40,7 @@
#include "nsAString.h" #include "nsAString.h"
class nsString; class nsString;
class nsCString;
// XXX should this normalize the code to keep a \u0000 at the end? // XXX should this normalize the code to keep a \u0000 at the end?
@ -205,6 +206,11 @@ public:
*/ */
void AppendTo(nsString& aString) const; void AppendTo(nsString& aString) const;
/**
* Append the contents of this string fragment to aCString
*/
void AppendTo(nsCString& aCString) const;
/** /**
* Make a copy of the fragments contents starting at offset for * Make a copy of the fragments contents starting at offset for
* count characters. The offset and count will be adjusted to * count characters. The offset and count will be adjusted to

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

@ -278,6 +278,18 @@ nsTextFragment::AppendTo(nsString& aString) const
} }
} }
void
nsTextFragment::AppendTo(nsCString& aCString) const
{
if (mState.mLength == 0) return;
if (mState.mIs2b) {
aCString.AppendWithConversion((PRUnichar *)m2b, mState.mLength);
} else {
aCString.Append((char *)m1b, mState.mLength);
}
}
void void
nsTextFragment::CopyTo(PRUnichar *aDest, PRInt32 aOffset, PRInt32 aCount) nsTextFragment::CopyTo(PRUnichar *aDest, PRInt32 aOffset, PRInt32 aCount)
{ {