diff options
author | Adrien Ollier <adr.ollier@hotmail.fr> | 2019-07-22 20:16:05 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-23 15:45:52 +0200 |
commit | 347b26ae3e332c206724fe5ec9d46fef38798281 (patch) | |
tree | d09d2a6159c0cc9a9b0efde9ca531f35671e7ef9 /writerfilter/source | |
parent | d367ee2f8c204f351072c0eb10259fd7aa497770 (diff) |
better implementation of RTFSprms::find
if not bFirst, then it is more efficient
to start the search from the end.
Change-Id: I89bcb3b70ada7746ab983878f2868f58b89f37a5
Signed-off-by: Adrien Ollier <adr.ollier@hotmail.fr>
Reviewed-on: https://gerrit.libreoffice.org/76126
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'writerfilter/source')
-rw-r--r-- | writerfilter/source/rtftok/rtfsprm.cxx | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx index b50d9b166344..109dd20474e5 100644 --- a/writerfilter/source/rtftok/rtfsprm.cxx +++ b/writerfilter/source/rtftok/rtfsprm.cxx @@ -59,20 +59,28 @@ std::string RTFSprm::toString() const RTFValue::Pointer_t RTFSprms::find(Id nKeyword, bool bFirst, bool bForWrite) { - RTFValue::Pointer_t pValue; - if (bForWrite) ensureCopyBeforeWrite(); - for (auto& rSprm : *m_pSprms) - if (rSprm.first == nKeyword) - { - if (bFirst) - return rSprm.second; + auto cmp = [&nKeyword](const std::pair<Id, RTFValue::Pointer_t>& raPair) -> bool { + return raPair.first == nKeyword; + }; - pValue = rSprm.second; - } - return pValue; + if (bFirst) + { + auto it = std::find_if(m_pSprms->begin(), m_pSprms->end(), cmp); + if (it != m_pSprms->end()) + return it->second; + } + else + // find last + { + auto rit = std::find_if(m_pSprms->rbegin(), m_pSprms->rend(), cmp); + if (rit != m_pSprms->rend()) + return rit->second; + } + + return RTFValue::Pointer_t{}; } void RTFSprms::set(Id nKeyword, const RTFValue::Pointer_t& pValue, RTFOverwrite eOverwrite) |