diff --git a/src/kleo/keygroup.cpp b/src/kleo/keygroup.cpp index 69240a4f5..465c1495b 100644 --- a/src/kleo/keygroup.cpp +++ b/src/kleo/keygroup.cpp @@ -1,75 +1,76 @@ /* kleo/keygroup.cpp This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include "keygroup.h" #include #include using namespace Kleo; using namespace GpgME; class KeyGroup::Private { public: explicit Private(const QString &name, const std::vector &keys); QString name; std::vector keys; }; KeyGroup::Private::Private(const QString &name_, const std::vector &keys_) : name(name_) , keys(keys_) { } KeyGroup::KeyGroup() : KeyGroup(QString(), {}) { } KeyGroup::~KeyGroup() = default; KeyGroup::KeyGroup(const QString &name, const std::vector &keys) : d(new Private(name, keys)) { } KeyGroup::KeyGroup(const KeyGroup &other) : d(new Private(*other.d)) { } KeyGroup &KeyGroup::operator=(const KeyGroup &other) { *d = *other.d; return *this; } KeyGroup::KeyGroup(KeyGroup &&other) = default; KeyGroup &KeyGroup::operator=(KeyGroup &&other) = default; bool KeyGroup::isNull() const { return !d || d->name.isEmpty(); } QString KeyGroup::name() const { return d ? d->name : QString(); } -std::vector Kleo::KeyGroup::keys() const +const std::vector &KeyGroup::keys() const { - return d ? d->keys : std::vector(); + static const std::vector empty; + return d ? d->keys : empty; } diff --git a/src/kleo/keygroup.h b/src/kleo/keygroup.h index 7a2bd7f77..b9e053bfe 100644 --- a/src/kleo/keygroup.h +++ b/src/kleo/keygroup.h @@ -1,56 +1,56 @@ /* kleo/keygroup.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2021 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef LIBKLEO_KEYGROUP_H #define LIBKLEO_KEYGROUP_H #include "kleo_export.h" #include #include class QString; namespace GpgME { class Key; } namespace Kleo { class KLEO_EXPORT KeyGroup { public: KeyGroup(); ~KeyGroup(); explicit KeyGroup(const QString &name, const std::vector &keys); KeyGroup(const KeyGroup &other); KeyGroup &operator=(const KeyGroup &other); KeyGroup(KeyGroup &&other); KeyGroup &operator=(KeyGroup &&other); bool isNull() const; QString name() const; - std::vector keys() const; + const std::vector &keys() const; private: class Private; std::unique_ptr d; }; } #endif // LIBKLEO_KEYGROUP_H