From 9f3eb23029e6773a3740ac3f8bb4ab01ee929c98 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Mon, 12 Jun 2023 00:08:02 +0000 Subject: [PATCH] Bug 1768317 - Make `InsertTextTransaction::GetData()` returns reference of its `mStringToInsert` r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D179521 --- editor/libeditor/InsertTextTransaction.cpp | 10 ++-------- editor/libeditor/InsertTextTransaction.h | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/editor/libeditor/InsertTextTransaction.cpp b/editor/libeditor/InsertTextTransaction.cpp index 8010fe32f65d..3a308dd4878f 100644 --- a/editor/libeditor/InsertTextTransaction.cpp +++ b/editor/libeditor/InsertTextTransaction.cpp @@ -157,9 +157,7 @@ NS_IMETHODIMP InsertTextTransaction::Merge(nsITransaction* aOtherTransaction, return NS_OK; } - nsAutoString otherData; - otherInsertTextTransaction->GetData(otherData); - mStringToInsert += otherData; + mStringToInsert += otherInsertTextTransaction->GetData(); *aDidMerge = true; MOZ_LOG(GetLogModule(), LogLevel::Debug, ("%p InsertTextTransaction::%s(aOtherTransaction=%p) returned true", @@ -169,12 +167,8 @@ NS_IMETHODIMP InsertTextTransaction::Merge(nsITransaction* aOtherTransaction, /* ============ private methods ================== */ -void InsertTextTransaction::GetData(nsString& aResult) { - aResult = mStringToInsert; -} - bool InsertTextTransaction::IsSequentialInsert( - InsertTextTransaction& aOtherTransaction) { + InsertTextTransaction& aOtherTransaction) const { return aOtherTransaction.mTextNode == mTextNode && aOtherTransaction.mOffset == mOffset + mStringToInsert.Length(); } diff --git a/editor/libeditor/InsertTextTransaction.h b/editor/libeditor/InsertTextTransaction.h index 6b78d107d707..8411d87abca8 100644 --- a/editor/libeditor/InsertTextTransaction.h +++ b/editor/libeditor/InsertTextTransaction.h @@ -56,7 +56,7 @@ class InsertTextTransaction final : public EditTransactionBase { /** * Return the string data associated with this transaction. */ - void GetData(nsString& aResult); + const nsString& GetData() const { return mStringToInsert; } template EditorDOMPointType SuggestPointToPutCaret() const { @@ -73,7 +73,7 @@ class InsertTextTransaction final : public EditTransactionBase { virtual ~InsertTextTransaction() = default; // Return true if aOtherTransaction immediately follows this transaction. - bool IsSequentialInsert(InsertTextTransaction& aOtherTrasaction); + bool IsSequentialInsert(InsertTextTransaction& aOtherTransaction) const; // The Text node to operate upon. RefPtr mTextNode;