[Libreoffice-commits] core.git: writerfilter/source
Adrien Ollier (via logerrit)
logerrit at kemper.freedesktop.org
Fri Aug 30 01:57:32 UTC 2019
writerfilter/source/rtftok/rtfsprm.cxx | 34 +++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
New commits:
commit ed71dcc9996c507ecb2bca24f38e09f66134fbfc
Author: Adrien Ollier <adr.ollier at hotmail.fr>
AuthorDate: Wed Jul 24 05:29:03 2019 +0200
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Fri Aug 30 03:56:42 2019 +0200
RTFSprms: code refactorization
Four lambda expressions were declared doing the same thing,
which leads to the creation of four internal different
types for the same thing. That makes no sense.
Class RTFSprms_compare allows to factorize this code and
makes code shorter where it is used.
Change-Id: I5ed6821a67a50e96d9425064841c2b3421323001
Signed-off-by: Adrien Ollier <adr.ollier at hotmail.fr>
Reviewed-on: https://gerrit.libreoffice.org/76214
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx
index 6ba986e6b987..5404dd9176ea 100644
--- a/writerfilter/source/rtftok/rtfsprm.cxx
+++ b/writerfilter/source/rtftok/rtfsprm.cxx
@@ -57,14 +57,30 @@ std::string RTFSprm::toString() const
}
#endif
+namespace
+{
+class RTFSprms_compare
+{
+ Id keyword;
+
+public:
+ RTFSprms_compare(Id kw)
+ : keyword{ kw }
+ {
+ }
+ bool operator()(const std::pair<Id, RTFValue::Pointer_t>& raPair) const
+ {
+ return raPair.first == keyword;
+ }
+};
+}
+
RTFValue::Pointer_t RTFSprms::find(Id nKeyword, bool bFirst, bool bForWrite)
{
if (bForWrite)
ensureCopyBeforeWrite();
- auto cmp = [&nKeyword](const std::pair<Id, RTFValue::Pointer_t>& raPair) -> bool {
- return raPair.first == nKeyword;
- };
+ RTFSprms_compare cmp{ nKeyword };
if (bFirst)
{
@@ -89,9 +105,7 @@ void RTFSprms::set(Id nKeyword, const RTFValue::Pointer_t& pValue, RTFOverwrite
if (eOverwrite == RTFOverwrite::YES_PREPEND)
{
- auto it = std::remove_if(
- m_pSprms->begin(), m_pSprms->end(),
- [nKeyword](const RTFSprms::Entry_t& rSprm) { return rSprm.first == nKeyword; });
+ auto it = std::remove_if(m_pSprms->begin(), m_pSprms->end(), RTFSprms_compare{ nKeyword });
m_pSprms->erase(it, m_pSprms->end());
m_pSprms->insert(m_pSprms->begin(), std::make_pair(nKeyword, pValue));
return;
@@ -121,9 +135,7 @@ bool RTFSprms::erase(Id nKeyword)
{
ensureCopyBeforeWrite();
- auto i = std::find_if(
- m_pSprms->begin(), m_pSprms->end(),
- [&nKeyword](RTFSprmsImpl::value_type& rEntry) { return rEntry.first == nKeyword; });
+ auto i = std::find_if(m_pSprms->begin(), m_pSprms->end(), RTFSprms_compare{ nKeyword });
if (i != m_pSprms->end())
{
m_pSprms->erase(i);
@@ -136,9 +148,7 @@ void RTFSprms::eraseLast(Id nKeyword)
{
ensureCopyBeforeWrite();
- auto i = std::find_if(
- m_pSprms->rbegin(), m_pSprms->rend(),
- [&nKeyword](RTFSprmsImpl::value_type& rEntry) { return rEntry.first == nKeyword; });
+ auto i = std::find_if(m_pSprms->rbegin(), m_pSprms->rend(), RTFSprms_compare{ nKeyword });
if (i != m_pSprms->rend())
m_pSprms->erase(std::next(i).base());
}
More information about the Libreoffice-commits
mailing list