[Libreoffice-commits] core.git: sw/inc sw/source
Bjoern Michaelsen
bjoern.michaelsen at libreoffice.org
Wed May 9 19:26:23 UTC 2018
sw/inc/calbck.hxx | 12 ++++--------
sw/source/core/attr/calbck.cxx | 24 ++++++++++++++++++------
2 files changed, 22 insertions(+), 14 deletions(-)
New commits:
commit c663523ae63b18ea7e85afeb47c0c97e1064aa05
Author: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
Date: Tue May 8 01:02:45 2018 +0200
no extra heap allocs by WriterMultiListener
Change-Id: I53fbc049e8462b09a1fe7fbdd4207032ddaf5a2b
Reviewed-on: https://gerrit.libreoffice.org/53955
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Björn Michaelsen <bjoern.michaelsen at libreoffice.org>
diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx
index cbe45ce74b48..9f809ea24dbd 100644
--- a/sw/inc/calbck.hxx
+++ b/sw/inc/calbck.hxx
@@ -106,14 +106,13 @@ class SW_DLLPUBLIC SwClient : public ::sw::WriterListener
protected:
// single argument ctors shall be explicit.
inline explicit SwClient( SwModify* pToRegisterIn );
- SwClient(SwClient&&);
// write access to pRegisteredIn shall be granted only to the object itself (protected access)
SwModify* GetRegisteredInNonConst() const { return m_pRegisteredIn; }
public:
-
SwClient() : m_pRegisteredIn(nullptr) {}
+ SwClient(SwClient&&) noexcept;
virtual ~SwClient() override;
// callbacks received from SwModify (friend class - so these methods can be private)
// should be called only from SwModify the client is registered in
@@ -209,15 +208,12 @@ namespace sw
class ListenerEntry;
class SW_DLLPUBLIC WriterMultiListener final
{
- #ifdef WNT
- typedef std::shared_ptr<ListenerEntry> pointer_t;
- #else
- typedef std::unique_ptr<ListenerEntry> pointer_t;
- #endif
SwClient& m_rToTell;
- std::vector<pointer_t> m_vDepends;
+ std::vector<ListenerEntry> m_vDepends;
public:
WriterMultiListener(SwClient& rToTell);
+ WriterMultiListener& operator=(WriterMultiListener const&) = delete; // MSVC2015 workaround
+ WriterMultiListener(WriterMultiListener const&) = delete; // MSVC2015 workaround
~WriterMultiListener();
void StartListening(SwModify* pDepend);
void EndListening(SwModify* pDepend);
diff --git a/sw/source/core/attr/calbck.cxx b/sw/source/core/attr/calbck.cxx
index e9774a10a716..3ab307bd6e24 100644
--- a/sw/source/core/attr/calbck.cxx
+++ b/sw/source/core/attr/calbck.cxx
@@ -34,6 +34,18 @@ namespace sw
public:
ListenerEntry(SwClient* pTellHim, SwModify * pDepend) : SwClient(pDepend), m_pToTell(pTellHim) {}
ListenerEntry(ListenerEntry&) = delete;
+ ListenerEntry& operator=(ListenerEntry const&) = delete;
+ ListenerEntry(ListenerEntry&& other) noexcept
+ : SwClient(std::move(other))
+ , m_pToTell(other.m_pToTell)
+ { }
+ ListenerEntry& operator=(ListenerEntry&& other) noexcept
+ {
+ m_pToTell = other.m_pToTell;
+ other.GetRegisteredIn()->Add(this);
+ other.EndListeningAll();
+ return *this;
+ }
/** get Client information */
virtual bool GetInfo( SfxPoolItem& rInfo) const override
@@ -65,7 +77,7 @@ namespace sw
sw::LegacyModifyHint::~LegacyModifyHint() {}
sw::ModifyChangedHint::~ModifyChangedHint() {}
-SwClient::SwClient(SwClient&& o)
+SwClient::SwClient(SwClient&& o) noexcept
: m_pRegisteredIn(nullptr)
{
if(o.m_pRegisteredIn)
@@ -343,16 +355,16 @@ sw::WriterMultiListener::~WriterMultiListener()
void sw::WriterMultiListener::StartListening(SwModify* pDepend)
{
EndListening(nullptr);
- m_vDepends.emplace_back(pointer_t(new ListenerEntry(&m_rToTell, pDepend)));
+ m_vDepends.emplace_back(ListenerEntry(&m_rToTell, pDepend));
}
bool sw::WriterMultiListener::IsListeningTo(const SwModify* const pBroadcaster)
{
return std::any_of(m_vDepends.begin(), m_vDepends.end(),
- [&pBroadcaster](const pointer_t& pListener)
+ [&pBroadcaster](const ListenerEntry& aListener)
{
- return pListener->GetRegisteredIn() == pBroadcaster;
+ return aListener.GetRegisteredIn() == pBroadcaster;
});
}
@@ -360,9 +372,9 @@ void sw::WriterMultiListener::EndListening(SwModify* pBroadcaster)
{
m_vDepends.erase(
std::remove_if( m_vDepends.begin(), m_vDepends.end(),
- [&pBroadcaster](const pointer_t& pListener)
+ [&pBroadcaster](const ListenerEntry& aListener)
{
- return pListener->GetRegisteredIn() == nullptr || pListener->GetRegisteredIn() == pBroadcaster;
+ return aListener.GetRegisteredIn() == nullptr || aListener.GetRegisteredIn() == pBroadcaster;
}),
m_vDepends.end());
}
More information about the Libreoffice-commits
mailing list