summaryrefslogtreecommitdiff
path: root/unoidl
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2018-10-17 00:16:56 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-17 09:14:15 +0200
commit87bd462eff0e746835bb4e449bdea19ff3749580 (patch)
tree02a6405889bb1913ea142aab2e4c0796bc0d0fc7 /unoidl
parentccb2a1f650bc505f8a4f1abebf8ce4f9396562a8 (diff)
Simplify containers iterations in unodevtools, unoidl
Use range-based loop or replace with STL functions. Change-Id: I3089a4d4a94eea849cad442b04906908908e4c27 Reviewed-on: https://gerrit.libreoffice.org/61854 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unoidl')
-rw-r--r--unoidl/source/unoidl-write.cxx109
1 files changed, 28 insertions, 81 deletions
diff --git a/unoidl/source/unoidl-write.cxx b/unoidl/source/unoidl-write.cxx
index 73dba8c77652..827e9ad0a4db 100644
--- a/unoidl/source/unoidl-write.cxx
+++ b/unoidl/source/unoidl-write.cxx
@@ -9,6 +9,7 @@
#include <sal/config.h>
+#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdlib>
@@ -445,6 +446,12 @@ void mapCursor(
}
}
+template<typename T>
+bool hasNotEmptyAnnotations(const std::vector<T>& v)
+{
+ return std::any_of(v.begin(), v.end(), [](const T& rItem) { return !rItem.annotations.empty(); });
+}
+
sal_uInt64 writeMap(
osl::File & file, std::map< OUString, Item > & map, std::size_t * rootSize)
{
@@ -458,12 +465,8 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::EnumTypeEntity > ent2(
static_cast< unoidl::EnumTypeEntity * >(
i.second.entity.get()));
- bool ann = !ent2->getAnnotations().empty();
- for (auto j(ent2->getMembers().begin());
- !ann && j != ent2->getMembers().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
+ bool ann = !ent2->getAnnotations().empty() ||
+ hasNotEmptyAnnotations(ent2->getMembers());
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann);
write32(file, ent2->getMembers().size());
@@ -480,12 +483,8 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
static_cast< unoidl::PlainStructTypeEntity * >(
i.second.entity.get()));
- bool ann = !ent2->getAnnotations().empty();
- for (auto j(ent2->getDirectMembers().begin());
- !ann && j != ent2->getDirectMembers().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
+ bool ann = !ent2->getAnnotations().empty() ||
+ hasNotEmptyAnnotations(ent2->getDirectMembers());
i.second.dataOffset = getOffset(file);
writeKind(
file, ent2.get(), ann, !ent2->getDirectBase().isEmpty());
@@ -508,12 +507,8 @@ sal_uInt64 writeMap(
static_cast<
unoidl::PolymorphicStructTypeTemplateEntity * >(
i.second.entity.get()));
- bool ann = !ent2->getAnnotations().empty();
- for (auto j(ent2->getMembers().begin());
- !ann && j != ent2->getMembers().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
+ bool ann = !ent2->getAnnotations().empty() ||
+ hasNotEmptyAnnotations(ent2->getMembers());
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann);
write32(file, ent2->getTypeParameters().size());
@@ -539,12 +534,8 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
static_cast< unoidl::ExceptionTypeEntity * >(
i.second.entity.get()));
- bool ann = !ent2->getAnnotations().empty();
- for (auto j(ent2->getDirectMembers().begin());
- !ann && j != ent2->getDirectMembers().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
+ bool ann = !ent2->getAnnotations().empty() ||
+ hasNotEmptyAnnotations(ent2->getDirectMembers());
i.second.dataOffset = getOffset(file);
writeKind(
file, ent2.get(), ann, !ent2->getDirectBase().isEmpty());
@@ -565,27 +556,11 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
static_cast< unoidl::InterfaceTypeEntity * >(
i.second.entity.get()));
- bool ann = !ent2->getAnnotations().empty();
- for (auto j(ent2->getDirectMandatoryBases().begin());
- !ann && j != ent2->getDirectMandatoryBases().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
- for (auto j(ent2->getDirectOptionalBases().begin());
- !ann && j != ent2->getDirectOptionalBases().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
- for (auto j(ent2->getDirectAttributes().begin());
- !ann && j != ent2->getDirectAttributes().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
- for (auto j(ent2->getDirectMethods().begin());
- !ann && j != ent2->getDirectMethods().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
+ bool ann = !ent2->getAnnotations().empty() ||
+ hasNotEmptyAnnotations(ent2->getDirectMandatoryBases()) ||
+ hasNotEmptyAnnotations(ent2->getDirectOptionalBases()) ||
+ hasNotEmptyAnnotations(ent2->getDirectAttributes()) ||
+ hasNotEmptyAnnotations(ent2->getDirectMethods());
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann);
write32(file, ent2->getDirectMandatoryBases().size());
@@ -757,11 +732,8 @@ sal_uInt64 writeMap(
&& ent2->getConstructors()[0].defaultConstructor;
bool ann = !ent2->getAnnotations().empty();
if (!dfltCtor) {
- for (auto j(ent2->getConstructors().begin());
- !ann && j != ent2->getConstructors().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
+ if (!ann)
+ ann = hasNotEmptyAnnotations(ent2->getConstructors());
}
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann, dfltCtor);
@@ -801,37 +773,12 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::AccumulationBasedServiceEntity > ent2(
static_cast< unoidl::AccumulationBasedServiceEntity * >(
i.second.entity.get()));
- bool ann = !ent2->getAnnotations().empty();
- for (auto j(ent2->getDirectMandatoryBaseServices().begin());
- !ann && j != ent2->getDirectMandatoryBaseServices().end();
- ++j)
- {
- ann = !j->annotations.empty();
- }
- for (auto j(ent2->getDirectOptionalBaseServices().begin());
- !ann && j != ent2->getDirectOptionalBaseServices().end();
- ++j)
- {
- ann = !j->annotations.empty();
- }
- for (auto j(ent2->getDirectMandatoryBaseInterfaces().begin());
- (!ann
- && j != ent2->getDirectMandatoryBaseInterfaces().end());
- ++j)
- {
- ann = !j->annotations.empty();
- }
- for (auto j(ent2->getDirectOptionalBaseInterfaces().begin());
- !ann && j != ent2->getDirectOptionalBaseInterfaces().end();
- ++j)
- {
- ann = !j->annotations.empty();
- }
- for (auto j(ent2->getDirectProperties().begin());
- !ann && j != ent2->getDirectProperties().end(); ++j)
- {
- ann = !j->annotations.empty();
- }
+ bool ann = !ent2->getAnnotations().empty() ||
+ hasNotEmptyAnnotations(ent2->getDirectMandatoryBaseServices()) ||
+ hasNotEmptyAnnotations(ent2->getDirectOptionalBaseServices()) ||
+ hasNotEmptyAnnotations(ent2->getDirectMandatoryBaseInterfaces()) ||
+ hasNotEmptyAnnotations(ent2->getDirectOptionalBaseInterfaces()) ||
+ hasNotEmptyAnnotations(ent2->getDirectProperties());
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann);
write32(file, ent2->getDirectMandatoryBaseServices().size());