Bug 1203871 - Part 5. Use mozilla::Move for rect array. r=masayuki
To optimize copy of text rect array, we should use mozilla::Move. Also, after using it, we should mark is invalid result into SetEventResult
MozReview-Commit-ID: HH9H7DhK12
--- a/dom/base/nsQueryContentEventResult.cpp
+++ b/dom/base/nsQueryContentEventResult.cpp
@@ -1,17 +1,18 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "nsQueryContentEventResult.h"
#include "nsIWidget.h"
#include "nsPoint.h"
+#include "nsQueryContentEventResult.h"
+#include "mozilla/Move.h"
#include "mozilla/TextEvents.h"
using namespace mozilla;
/******************************************************************************
* Is*PropertyAvailable() methods which check if the property is available
* (valid) with the event message.
******************************************************************************/
@@ -217,26 +218,28 @@ nsQueryContentEventResult::GetCharacterR
*aWidth = mRectArray[aOffset].width;
*aHeight = mRectArray[aOffset].height;
return NS_OK;
}
void
nsQueryContentEventResult::SetEventResult(nsIWidget* aWidget,
- const WidgetQueryContentEvent &aEvent)
+ WidgetQueryContentEvent &aEvent)
{
mEventMessage = aEvent.mMessage;
mSucceeded = aEvent.mSucceeded;
mReversed = aEvent.mReply.mReversed;
mRect = aEvent.mReply.mRect;
mOffset = aEvent.mReply.mOffset;
mTentativeCaretOffset = aEvent.mReply.mTentativeCaretOffset;
mString = aEvent.mReply.mString;
- mRectArray = aEvent.mReply.mRectArray;
+ mRectArray = mozilla::Move(aEvent.mReply.mRectArray);
+ // Mark as result that is longer used.
+ aEvent.mSucceeded = false;
if (!IsRectRelatedPropertyAvailable(mEventMessage) ||
!aWidget || !mSucceeded) {
return;
}
nsIWidget* topWidget = aWidget->GetTopLevelWidget();
if (!topWidget || topWidget == aWidget) {
--- a/dom/base/nsQueryContentEventResult.h
+++ b/dom/base/nsQueryContentEventResult.h
@@ -19,17 +19,17 @@ class nsIWidget;
class nsQueryContentEventResult final : public nsIQueryContentEventResult
{
public:
nsQueryContentEventResult();
NS_DECL_ISUPPORTS
NS_DECL_NSIQUERYCONTENTEVENTRESULT
void SetEventResult(nsIWidget* aWidget,
- const mozilla::WidgetQueryContentEvent &aEvent);
+ mozilla::WidgetQueryContentEvent& aEvent);
protected:
~nsQueryContentEventResult();
mozilla::EventMessage mEventMessage;
uint32_t mOffset;
uint32_t mTentativeCaretOffset;
--- a/widget/ContentCache.cpp
+++ b/widget/ContentCache.cpp
@@ -7,16 +7,17 @@
#include "mozilla/ContentCache.h"
#include "mozilla/IMEStateManager.h"
#include "mozilla/Logging.h"
#include "mozilla/TextComposition.h"
#include "mozilla/TextEvents.h"
#include "nsIWidget.h"
#include "mozilla/RefPtr.h"
+#include "mozilla/Move.h"
namespace mozilla {
using namespace widget;
static const char*
GetBoolName(bool aBool)
{
@@ -309,17 +310,17 @@ ContentCacheInChild::CacheTextRects(nsIW
uint32_t length = textComposition->LastData().Length();
mTextRectArray.mStart = mCompositionStart;
nsEventStatus status = nsEventStatus_eIgnore;
WidgetQueryContentEvent textRects(true, eQueryTextRectArray, aWidget);
textRects.InitForQueryTextRectArray(mTextRectArray.mStart, length);
aWidget->DispatchEvent(&textRects, status);
- mTextRectArray.mRects = textRects.mReply.mRectArray;
+ mTextRectArray.mRects = Move(textRects.mReply.mRectArray);
}
if (mTextRectArray.InRange(mSelection.mAnchor)) {
mSelection.mAnchorCharRect = mTextRectArray.GetRect(mSelection.mAnchor);
} else {
LayoutDeviceIntRect charRect;
if (NS_WARN_IF(!QueryCharRect(aWidget, mSelection.mAnchor, charRect))) {
MOZ_LOG(sContentCacheLog, LogLevel::Error,