From 3e64065612acec2eb29aa21e2b515953422256d7 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Wed, 14 Aug 2019 22:27:06 +0300 Subject: Optimize NestedKeyImpl::openKeys * Use const methods of Sequence * Get rid of extra loop over localSeq * Simplify default keys insert condition Change-Id: I112c0a53d3ebfc2ff54a4ac904e6e112beaf3cdd Reviewed-on: https://gerrit.libreoffice.org/77472 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov --- stoc/source/defaultregistry/defaultregistry.cxx | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'stoc') diff --git a/stoc/source/defaultregistry/defaultregistry.cxx b/stoc/source/defaultregistry/defaultregistry.cxx index bfa698b13b91..71a637309c5a 100644 --- a/stoc/source/defaultregistry/defaultregistry.cxx +++ b/stoc/source/defaultregistry/defaultregistry.cxx @@ -755,33 +755,27 @@ Sequence< Reference< XRegistryKey > > SAL_CALL NestedKeyImpl::openKeys( ) defaultSeq = m_defaultKey->getKeyNames(); } - sal_uInt32 local = localSeq.getLength(); - sal_uInt32 def = defaultSeq.getLength(); - sal_uInt32 len = static_cast(std::count_if(localSeq.begin(), localSeq.end(), - [&defaultSeq](const OUString& rLocal) { return comphelper::findValue(defaultSeq, rLocal) != -1; })); - - Sequence< Reference > retSeq(local + def - len); + std::vector< Reference > retVec; + retVec.reserve(localSeq.getLength() + defaultSeq.getLength()); auto lKeyNameToRegKey = [this](const OUString& rName) -> Reference { sal_Int32 lastIndex = rName.lastIndexOf('/'); OUString name = rName.copy(lastIndex); return new NestedKeyImpl(name, this); }; - std::transform(localSeq.begin(), localSeq.end(), retSeq.begin(), lKeyNameToRegKey); - sal_uInt32 k = local; - for (const auto& rDef : std::as_const(defaultSeq)) - { - bool insert = std::none_of(retSeq.begin(), std::next(retSeq.begin(), local), - [&rDef](const Reference& rKey) { return rKey->getKeyName() == rDef; }); + for (const auto& rKeyName : std::as_const(localSeq)) + retVec.push_back(lKeyNameToRegKey(rKeyName)); - if ( insert ) + for (const auto& rKeyName : std::as_const(defaultSeq)) + { + if ( comphelper::findValue(localSeq, rKeyName) == -1 ) { - retSeq.getArray()[k++] = lKeyNameToRegKey(rDef); + retVec.push_back(lKeyNameToRegKey(rKeyName)); } } - return retSeq; + return comphelper::containerToSequence(retVec); } -- cgit