summaryrefslogtreecommitdiffstats
path: root/extensions/spellcheck/src
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-04-17 05:28:43 -0400
committerMatt A. Tobin <email@mattatobin.com>2020-04-17 05:28:43 -0400
commit940d191ef8b61309f4ea83d0fea77828f361251b (patch)
tree328a57b6d2e2b018343e2c5d20e0602d613f0e19 /extensions/spellcheck/src
parentef689a705ffdd79cdeeca8e68438b4ad6597f38d (diff)
downloadUXP-940d191ef8b61309f4ea83d0fea77828f361251b.tar
UXP-940d191ef8b61309f4ea83d0fea77828f361251b.tar.gz
UXP-940d191ef8b61309f4ea83d0fea77828f361251b.tar.lz
UXP-940d191ef8b61309f4ea83d0fea77828f361251b.tar.xz
UXP-940d191ef8b61309f4ea83d0fea77828f361251b.zip
Bug 1367683 - Optimize initializing nsRange
Tag #1375
Diffstat (limited to 'extensions/spellcheck/src')
-rw-r--r--extensions/spellcheck/src/mozInlineSpellChecker.cpp68
-rw-r--r--extensions/spellcheck/src/mozInlineSpellChecker.h6
-rw-r--r--extensions/spellcheck/src/mozInlineSpellWordUtil.cpp8
3 files changed, 50 insertions, 32 deletions
diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.cpp b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
index 96011a37e..118035aa5 100644
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -164,16 +164,23 @@ mozInlineSpellStatus::InitForEditorChange(
NS_ENSURE_SUCCESS(rv, rv);
if (cmpResult < 0) {
// previous anchor node is before the current anchor
- rv = mRange->SetStart(aPreviousNode, aPreviousOffset);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = mRange->SetEnd(aAnchorNode, aAnchorOffset);
+ nsCOMPtr<nsINode> previousNode = do_QueryInterface(aPreviousNode);
+ nsCOMPtr<nsINode> anchorNode = do_QueryInterface(aAnchorNode);
+ rv = mRange->SetStartAndEnd(previousNode, aPreviousOffset,
+ anchorNode, aAnchorOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
} else {
// previous anchor node is after (or the same as) the current anchor
- rv = mRange->SetStart(aAnchorNode, aAnchorOffset);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = mRange->SetEnd(aPreviousNode, aPreviousOffset);
+ nsCOMPtr<nsINode> previousNode = do_QueryInterface(aPreviousNode);
+ nsCOMPtr<nsINode> anchorNode = do_QueryInterface(aAnchorNode);
+ rv = mRange->SetStartAndEnd(anchorNode, aAnchorOffset,
+ previousNode, aPreviousOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
}
- NS_ENSURE_SUCCESS(rv, rv);
// On insert save this range: DoSpellCheck optimizes things in this range.
// Otherwise, just leave this nullptr.
@@ -454,17 +461,19 @@ mozInlineSpellStatus::GetDocument(nsIDOMDocument** aDocument)
nsresult
mozInlineSpellStatus::PositionToCollapsedRange(nsIDOMDocument* aDocument,
- nsIDOMNode* aNode, int32_t aOffset, nsIDOMRange** aRange)
+ nsIDOMNode* aNode,
+ int32_t aOffset,
+ nsRange** aRange)
{
*aRange = nullptr;
- nsCOMPtr<nsIDOMRange> range;
- nsresult rv = aDocument->CreateRange(getter_AddRefs(range));
- NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr<nsINode> documentNode = do_QueryInterface(aDocument);
+ RefPtr<nsRange> range = new nsRange(documentNode);
- rv = range->SetStart(aNode, aOffset);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = range->SetEnd(aNode, aOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+ nsresult rv = range->CollapseTo(node, aOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
range.swap(*aRange);
return NS_OK;
@@ -1164,9 +1173,8 @@ mozInlineSpellChecker::MakeSpellCheckRange(
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
- nsCOMPtr<nsIDOMRange> range;
- rv = doc->CreateRange(getter_AddRefs(range));
- NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr<nsINode> documentNode = do_QueryInterface(doc);
+ RefPtr<nsRange> range = new nsRange(documentNode);
// possibly use full range of the editor
nsCOMPtr<nsIDOMElement> rootElem;
@@ -1198,15 +1206,23 @@ mozInlineSpellChecker::MakeSpellCheckRange(
if (aStartNode == aEndNode && aStartOffset == aEndOffset)
return NS_OK;
- rv = range->SetStart(aStartNode, aStartOffset);
- NS_ENSURE_SUCCESS(rv, rv);
- if (aEndOffset)
- rv = range->SetEnd(aEndNode, aEndOffset);
- else
- rv = range->SetEndAfter(aEndNode);
- NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr<nsINode> startNode = do_QueryInterface(aStartNode);
+ nsCOMPtr<nsINode> endNode = do_QueryInterface(aEndNode);
+ if (aEndOffset) {
+ rv = range->SetStartAndEnd(startNode, aStartOffset, endNode, aEndOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
+ } else {
+ int32_t endOffset = -1;
+ endNode = nsRange::GetParentAndOffsetAfter(endNode, &endOffset);
+ rv = range->SetStartAndEnd(startNode, aStartOffset, endNode, endOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
+ }
- *aRange = static_cast<nsRange*>(range.forget().take());
+ range.swap(*aRange);
return NS_OK;
}
diff --git a/extensions/spellcheck/src/mozInlineSpellChecker.h b/extensions/spellcheck/src/mozInlineSpellChecker.h
index 86d91c2c0..52261f22b 100644
--- a/extensions/spellcheck/src/mozInlineSpellChecker.h
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.h
@@ -85,7 +85,7 @@ public:
// (such as for the intial check of everything).
//
// For mOp == eOpNavigation, this is the NEW position of the cursor
- nsCOMPtr<nsIDOMRange> mAnchorRange;
+ RefPtr<nsRange> mAnchorRange;
// -----
// The following members are only for navigation events and are only
@@ -93,7 +93,7 @@ public:
// -----
// this is the OLD position of the cursor
- nsCOMPtr<nsIDOMRange> mOldNavigationAnchorRange;
+ RefPtr<nsRange> mOldNavigationAnchorRange;
// Set when we should force checking the current word. See
// mozInlineSpellChecker::HandleNavigationEvent for a description of why we
@@ -111,7 +111,7 @@ protected:
nsresult GetDocument(nsIDOMDocument** aDocument);
nsresult PositionToCollapsedRange(nsIDOMDocument* aDocument,
nsIDOMNode* aNode, int32_t aOffset,
- nsIDOMRange** aRange);
+ nsRange** aRange);
};
class mozInlineSpellChecker final : public nsIInlineSpellChecker,
diff --git a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
index 3aef1533d..460ac46b8 100644
--- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
@@ -336,9 +336,11 @@ mozInlineSpellWordUtil::MakeRange(NodeOffset aBegin, NodeOffset aEnd,
return NS_ERROR_NOT_INITIALIZED;
RefPtr<nsRange> range = new nsRange(aBegin.mNode);
- nsresult rv = range->Set(aBegin.mNode, aBegin.mOffset,
- aEnd.mNode, aEnd.mOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ nsresult rv = range->SetStartAndEnd(aBegin.mNode, aBegin.mOffset,
+ aEnd.mNode, aEnd.mOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
range.forget(aRange);
return NS_OK;