Bug 1367683 Optimize initializing nsRange r=smaug
nsRange::DoSetRange() adds/remove its root to/from mutation observer, initializes common ancestor, registers itself to the common ancestor, unregisters itself from old common ancestor, and notifies selection listeners of selection change. However, those runtime cost is expensive but on the other hand, a lot of callers set both start and end of the range and that causes calling DoSetRange() twice. This patch renames Set() to SetStartAndEnd() for easier to understand the meaning and make it call DoSetRange() only once. MozReview-Commit-ID: FRV55tuBAgg
This commit is contained in:
@@ -755,12 +755,12 @@ nsTextControlFrame::SetSelectionInternal(nsIDOMNode *aStartNode,
|
||||
// we have access to the node.
|
||||
nsCOMPtr<nsINode> start = do_QueryInterface(aStartNode);
|
||||
nsCOMPtr<nsINode> end = do_QueryInterface(aEndNode);
|
||||
// XXXbz nsRange::Set 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, Set() will simply error out, which is not too bad
|
||||
// for a case we don't expect to happen.
|
||||
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!
|
||||
|
||||
Reference in New Issue
Block a user