summaryrefslogtreecommitdiff
path: root/layout
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 /layout
parentef689a705ffdd79cdeeca8e68438b4ad6597f38d (diff)
downloaduxp-940d191ef8b61309f4ea83d0fea77828f361251b.tar.gz
Bug 1367683 - Optimize initializing nsRange
Tag #1375
Diffstat (limited to 'layout')
-rw-r--r--layout/forms/nsTextControlFrame.cpp7
-rw-r--r--layout/generic/nsSelection.cpp85
-rw-r--r--layout/printing/nsPrintEngine.cpp14
3 files changed, 46 insertions, 60 deletions
diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp
index aa3185d39a..b34e132e60 100644
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -758,7 +758,12 @@ nsTextControlFrame::SetSelectionInternal(nsIDOMNode *aStartNode,
// we have access to the node.
nsCOMPtr<nsINode> start = do_QueryInterface(aStartNode);
nsCOMPtr<nsINode> end = do_QueryInterface(aEndNode);
- nsresult rv = range->Set(start, aStartOffset, end, aEndOffset);
+ // XXXbz nsRange::SetStartAndEnd takes int32_t (and ranges generally work on
+ // int32_t), but we're passing uint32_t. The good news is that at this point
+ // our endpoints should really be within our length, so not really that big.
+ // And if they _are_ that big, SetStartAndEnd() will simply error out, which
+ // is not too bad for a case we don't expect to happen.
+ nsresult rv = range->SetStartAndEnd(start, aStartOffset, end, aEndOffset);
NS_ENSURE_SUCCESS(rv, rv);
// Get the selection, clear it and add the new range to it!
diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp
index 5ccb2d8bf8..f44ff7ea12 100644
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -1788,8 +1788,7 @@ nsFrameSelection::TakeFocus(nsIContent* aNewFocus,
RefPtr<nsRange> newRange = new nsRange(aNewFocus);
- newRange->SetStart(aNewFocus, aContentOffset);
- newRange->SetEnd(aNewFocus, aContentOffset);
+ newRange->CollapseTo(aNewFocus, aContentOffset);
mDomSelections[index]->AddRange(newRange);
mBatching = batching;
mChangesDuringBatching = changes;
@@ -3352,10 +3351,11 @@ nsFrameSelection::CreateAndAddRange(nsINode *aParentNode, int32_t aOffset)
RefPtr<nsRange> range = new nsRange(aParentNode);
// Set range around child at given offset
- nsresult result = range->SetStart(aParentNode, aOffset);
- if (NS_FAILED(result)) return result;
- result = range->SetEnd(aParentNode, aOffset+1);
- if (NS_FAILED(result)) return result;
+ nsresult rv = range->SetStartAndEnd(aParentNode, aOffset,
+ aParentNode, aOffset + 1);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
if (!mDomSelections[index])
@@ -3780,13 +3780,12 @@ Selection::SubtractRange(RangeData* aRange, nsRange* aSubtract,
// We need to add a new RangeData to the output, running from
// the end of aSubtract to the end of range
RefPtr<nsRange> postOverlap = new nsRange(aSubtract->GetEndParent());
-
- rv =
- postOverlap->SetStart(aSubtract->GetEndParent(), aSubtract->EndOffset());
- NS_ENSURE_SUCCESS(rv, rv);
- rv =
- postOverlap->SetEnd(range->GetEndParent(), range->EndOffset());
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = postOverlap->SetStartAndEnd(
+ aSubtract->GetEndParent(), aSubtract->EndOffset(),
+ range->GetEndParent(), range->EndOffset());
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
if (!postOverlap->Collapsed()) {
if (!aOutput->InsertElementAt(0, RangeData(postOverlap)))
return NS_ERROR_OUT_OF_MEMORY;
@@ -3799,12 +3798,12 @@ Selection::SubtractRange(RangeData* aRange, nsRange* aSubtract,
// the start of the range to the start of aSubtract
RefPtr<nsRange> preOverlap = new nsRange(range->GetStartParent());
- nsresult rv =
- preOverlap->SetStart(range->GetStartParent(), range->StartOffset());
- NS_ENSURE_SUCCESS(rv, rv);
- rv =
- preOverlap->SetEnd(aSubtract->GetStartParent(), aSubtract->StartOffset());
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = preOverlap->SetStartAndEnd(
+ range->GetStartParent(), range->StartOffset(),
+ aSubtract->GetStartParent(), aSubtract->StartOffset());
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
if (!preOverlap->Collapsed()) {
if (!aOutput->InsertElementAt(0, RangeData(preOverlap)))
@@ -5186,12 +5185,7 @@ Selection::Collapse(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv)
}
RefPtr<nsRange> range = new nsRange(parentNode);
- result = range->SetEnd(parentNode, aOffset);
- if (NS_FAILED(result)) {
- aRv.Throw(result);
- return;
- }
- result = range->SetStart(parentNode, aOffset);
+ result = range->CollapseTo(parentNode, aOffset);
if (NS_FAILED(result)) {
aRv.Throw(result);
return;
@@ -5579,11 +5573,8 @@ Selection::Extend(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv)
return;
}
SetDirection(eDirNext);
- res = difRange->SetEnd(range->GetEndParent(), range->EndOffset());
- nsresult tmp = difRange->SetStart(focusNode, focusOffset);
- if (NS_FAILED(tmp)) {
- res = tmp;
- }
+ res = difRange->SetStartAndEnd(focusNode, focusOffset,
+ range->GetEndParent(), range->EndOffset());
if (NS_FAILED(res)) {
aRv.Throw(res);
return;
@@ -5611,11 +5602,8 @@ Selection::Extend(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv)
}
else if (result3 <= 0 && result2 >= 0) {//a,2,1 or a2,1 or a,21 or a21
//deselect from 2 to 1
- res = difRange->SetEnd(focusNode, focusOffset);
- difRange->SetStart(aParentNode, aOffset, aRv);
- if (aRv.Failed()) {
- return;
- }
+ res = difRange->SetStartAndEnd(&aParentNode, aOffset,
+ focusNode, focusOffset);
if (NS_FAILED(res)) {
aRv.Throw(res);
return;
@@ -5678,11 +5666,8 @@ Selection::Extend(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv)
}
else if (result2 <= 0 && result3 >= 0) {//1,2,a or 12,a or 1,2a or 12a
//deselect from 1 to 2
- difRange->SetEnd(aParentNode, aOffset, aRv);
- res = difRange->SetStart(focusNode, focusOffset);
- if (aRv.Failed()) {
- return;
- }
+ res = difRange->SetStartAndEnd(focusNode, focusOffset,
+ &aParentNode, aOffset);
if (NS_FAILED(res)) {
aRv.Throw(res);
return;
@@ -5713,15 +5698,9 @@ Selection::Extend(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv)
}
//deselect from a to 1
if (focusNode != anchorNode || focusOffset!= anchorOffset) {//if collapsed diff dont do anything
- res = difRange->SetStart(anchorNode, anchorOffset);
- nsresult tmp = difRange->SetEnd(focusNode, focusOffset);
- if (NS_FAILED(tmp)) {
- res = tmp;
- }
- tmp = SetAnchorFocusToRange(range);
- if (NS_FAILED(tmp)) {
- res = tmp;
- }
+ res = difRange->SetStartAndEnd(anchorNode, anchorOffset,
+ focusNode, focusOffset);
+ nsresult tmp = SetAnchorFocusToRange(range);
if (NS_FAILED(res)) {
aRv.Throw(res);
return;
@@ -5746,11 +5725,9 @@ Selection::Extend(nsINode& aParentNode, uint32_t aOffset, ErrorResult& aRv)
return;
}
SetDirection(eDirPrevious);
- res = difRange->SetEnd(focusNode, focusOffset);
- nsresult tmp = difRange->SetStart(range->GetStartParent(), range->StartOffset());
- if (NS_FAILED(tmp)) {
- res = tmp;
- }
+ res = difRange->SetStartAndEnd(
+ range->GetStartParent(), range->StartOffset(),
+ focusNode, focusOffset);
if (NS_FAILED(res)) {
aRv.Throw(res);
return;
diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp
index f2db53250e..0c455f563f 100644
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -2449,13 +2449,17 @@ CloneRangeToSelection(nsRange* aRange, nsIDocument* aDoc,
NS_ENSURE_TRUE_VOID(newStart && newEnd);
nsCOMPtr<nsINode> newStartNode = do_QueryInterface(newStart);
- NS_ENSURE_TRUE_VOID(newStartNode);
+ nsCOMPtr<nsINode> newEndNode = do_QueryInterface(newEnd);
+ if (NS_WARN_IF(!newStartNode) || NS_WARN_IF(!newEndNode)) {
+ return;
+ }
RefPtr<nsRange> range = new nsRange(newStartNode);
- nsresult rv = range->SetStart(newStartNode, startOffset);
- NS_ENSURE_SUCCESS_VOID(rv);
- rv = range->SetEnd(newEnd, endOffset);
- NS_ENSURE_SUCCESS_VOID(rv);
+ nsresult rv =
+ range->SetStartAndEnd(newStartNode, startOffset, newEndNode, endOffset);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return;
+ }
aSelection->AddRange(range);
}