summaryrefslogtreecommitdiff
path: root/sw/inc/docary.hxx
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-05-03 13:04:08 +0200
committerMichael Stahl <mstahl@redhat.com>2017-05-03 14:07:11 +0200
commit8d31f114327e77c48c8cdc804e1e399ebeadd27c (patch)
treeb765acb4932d56499a36acc68c55d52a037c2d58 /sw/inc/docary.hxx
parent01575a06725648188d51de90323a6f1da97ef7a9 (diff)
tdf#88555 sw: reduce usage of dynamic_cast in SwFormatsModifyBase::Contains
This is a bad idea as the function is sometimes used to check if a SwFormat has been deleted, which can happen in Undo. Replace with ContainsFormat() and IsAlive(), and don't require a non-const SwFormat parameter so that the dynamic_cast using one isn't called all the time but only called once where it's safe. Change-Id: Ib74b79629f5c8ed432a912ada5974a6d816e7d31
Diffstat (limited to 'sw/inc/docary.hxx')
-rw-r--r--sw/inc/docary.hxx13
1 files changed, 9 insertions, 4 deletions
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 10e41d68f901..a63bb34cc307 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -23,6 +23,7 @@
#include <vector>
#include <set>
#include <algorithm>
+#include <type_traits>
#include <o3tl/sorted_vector.hxx>
#include <boost/multi_index_container.hpp>
@@ -135,7 +136,8 @@ public:
return it == end() ? SIZE_MAX : it - begin();
}
- bool Contains(Value const& p) const
+ /// check that given format is still alive (i.e. contained here)
+ bool IsAlive(typename std::remove_pointer<Value>::type const*const p) const
{ return std::find(begin(), end(), p) != end(); }
static void dumpAsXml(struct _xmlTextWriter* /*pWriter*/) {};
@@ -158,9 +160,12 @@ public:
size_t GetPos(const SwFormat *p) const
{ return SwVectorModifyBase<Value>::GetPos( static_cast<Value>( const_cast<SwFormat*>( p ) ) ); }
- bool Contains(const SwFormat *p) const {
- Value p2 = dynamic_cast<Value>(const_cast<SwFormat*>(p));
- return p2 != nullptr && SwVectorModifyBase<Value>::Contains(p2);
+
+ /// check if given format is contained here
+ /// @precond pFormat must not have been deleted
+ bool ContainsFormat(SwFormat const*const pFormat) const {
+ Value p = dynamic_cast<Value>(const_cast<SwFormat*>(pFormat));
+ return p != nullptr && SwVectorModifyBase<Value>::IsAlive(p);
}
};