mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 582863 - Spell checker shouldn't copy the text node contents unnecessarily; r=roc a=blocking2.0+
--HG-- extra : rebase_source : e134b15a712630b542b7b499e15a16727350bea6
This commit is contained in:
parent
9b8f299714
commit
865dbccfd8
@ -42,7 +42,6 @@
|
||||
*/
|
||||
|
||||
#include "nsTextFragment.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsMemory.h"
|
||||
@ -241,27 +240,6 @@ nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength)
|
||||
mState.mLength = aLength;
|
||||
}
|
||||
|
||||
void
|
||||
nsTextFragment::AppendTo(nsAString& aString) const
|
||||
{
|
||||
if (mState.mIs2b) {
|
||||
aString.Append(m2b, mState.mLength);
|
||||
} else {
|
||||
AppendASCIItoUTF16(Substring(m1b, m1b + mState.mLength),
|
||||
aString);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsTextFragment::AppendTo(nsAString& aString, PRInt32 aOffset, PRInt32 aLength) const
|
||||
{
|
||||
if (mState.mIs2b) {
|
||||
aString.Append(m2b + aOffset, aLength);
|
||||
} else {
|
||||
AppendASCIItoUTF16(Substring(m1b + aOffset, m1b + aOffset + aLength), aString);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsTextFragment::CopyTo(PRUnichar *aDest, PRInt32 aOffset, PRInt32 aCount)
|
||||
{
|
||||
|
@ -44,7 +44,7 @@
|
||||
#ifndef nsTextFragment_h___
|
||||
#define nsTextFragment_h___
|
||||
|
||||
#include "nsAString.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTraceRefcnt.h"
|
||||
class nsString;
|
||||
class nsCString;
|
||||
@ -165,14 +165,27 @@ public:
|
||||
/**
|
||||
* Append the contents of this string fragment to aString
|
||||
*/
|
||||
void AppendTo(nsAString& aString) const;
|
||||
void AppendTo(nsAString& aString) const {
|
||||
if (mState.mIs2b) {
|
||||
aString.Append(m2b, mState.mLength);
|
||||
} else {
|
||||
AppendASCIItoUTF16(Substring(m1b, m1b + mState.mLength),
|
||||
aString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a substring of the contents of this string fragment to aString.
|
||||
* @param aOffset where to start the substring in this text fragment
|
||||
* @param aLength the length of the substring
|
||||
*/
|
||||
void AppendTo(nsAString& aString, PRInt32 aOffset, PRInt32 aLength) const;
|
||||
void AppendTo(nsAString& aString, PRInt32 aOffset, PRInt32 aLength) const {
|
||||
if (mState.mIs2b) {
|
||||
aString.Append(m2b + aOffset, aLength);
|
||||
} else {
|
||||
AppendASCIItoUTF16(Substring(m1b + aOffset, m1b + aOffset + aLength), aString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a copy of the fragments contents starting at offset for
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "nsUnicharUtilCIID.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsTextFragment.h"
|
||||
|
||||
// IsIgnorableCharacter
|
||||
//
|
||||
@ -429,13 +430,6 @@ IsBRElement(nsIDOMNode* aNode)
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
static void
|
||||
GetNodeText(nsIDOMNode* aNode, nsAutoString& aText)
|
||||
{
|
||||
nsresult rv = aNode->GetNodeValue(aText);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to get node text");
|
||||
}
|
||||
|
||||
// Find the previous node in the DOM tree in preorder. This isn't fast because
|
||||
// one call to GetPrevSibling can be O(N) in the number of siblings...
|
||||
static nsIDOMNode*
|
||||
@ -480,10 +474,12 @@ ContainsDOMWordSeparator(nsIDOMNode* aNode, PRInt32 aBeforeOffset,
|
||||
if (!IsTextNode(aNode))
|
||||
return PR_FALSE;
|
||||
|
||||
nsAutoString str;
|
||||
GetNodeText(aNode, str);
|
||||
for (PRInt32 i = NS_MIN(aBeforeOffset, PRInt32(str.Length())) - 1; i >= 0; --i) {
|
||||
if (IsDOMWordSeparator(str.CharAt(i))) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
||||
NS_ASSERTION(content, "Where is our content?");
|
||||
const nsTextFragment* textFragment = content->GetText();
|
||||
NS_ASSERTION(textFragment, "Where is our text?");
|
||||
for (PRInt32 i = NS_MIN(aBeforeOffset, PRInt32(textFragment->GetLength())) - 1; i >= 0; --i) {
|
||||
if (IsDOMWordSeparator(textFragment->CharAt(i))) {
|
||||
*aSeparatorOffset = i;
|
||||
return PR_TRUE;
|
||||
}
|
||||
@ -584,7 +580,6 @@ mozInlineSpellWordUtil::BuildSoftText()
|
||||
PRBool seenSoftEnd = PR_FALSE;
|
||||
// Leave this outside the loop so large heap string allocations can be reused
|
||||
// across iterations
|
||||
nsAutoString str;
|
||||
while (node) {
|
||||
if (node == mSoftEnd.mNode) {
|
||||
seenSoftEnd = PR_TRUE;
|
||||
@ -592,14 +587,17 @@ mozInlineSpellWordUtil::BuildSoftText()
|
||||
|
||||
PRBool exit = PR_FALSE;
|
||||
if (IsTextNode(node)) {
|
||||
GetNodeText(node, str);
|
||||
PRInt32 lastOffsetInNode = str.Length();
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
||||
NS_ASSERTION(content, "Where is our content?");
|
||||
const nsTextFragment* textFragment = content->GetText();
|
||||
NS_ASSERTION(textFragment, "Where is our text?");
|
||||
PRInt32 lastOffsetInNode = textFragment->GetLength();
|
||||
|
||||
if (seenSoftEnd) {
|
||||
// check whether we can stop after this
|
||||
for (PRInt32 i = node == mSoftEnd.mNode ? mSoftEnd.mOffset : 0;
|
||||
i < PRInt32(str.Length()); ++i) {
|
||||
if (IsDOMWordSeparator(str.CharAt(i))) {
|
||||
i < PRInt32(textFragment->GetLength()); ++i) {
|
||||
if (IsDOMWordSeparator(textFragment->CharAt(i))) {
|
||||
exit = PR_TRUE;
|
||||
// stop at the first separator after the soft end point
|
||||
lastOffsetInNode = i;
|
||||
@ -612,7 +610,7 @@ mozInlineSpellWordUtil::BuildSoftText()
|
||||
PRInt32 len = lastOffsetInNode - firstOffsetInNode;
|
||||
mSoftTextDOMMapping.AppendElement(
|
||||
DOMTextMapping(NodeOffset(node, firstOffsetInNode), mSoftText.Length(), len));
|
||||
mSoftText.Append(Substring(str, firstOffsetInNode, len));
|
||||
textFragment->AppendTo(mSoftText, firstOffsetInNode, len);
|
||||
}
|
||||
|
||||
firstOffsetInNode = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user