From e48ea5f23a6a1601e8eeb6d0594f8f0d89f47fdb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 Feb 2017 12:38:27 +0100 Subject: [PATCH] Instance: add method FindPartition() --- src/Instance.cxx | 10 ++++++++++ src/Instance.hxx | 7 +++++++ src/command/PartitionCommands.cxx | 8 ++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Instance.cxx b/src/Instance.cxx index 5d7584e41..9b6c8ac65 100644 --- a/src/Instance.cxx +++ b/src/Instance.cxx @@ -39,6 +39,16 @@ Instance::Instance() { } +Partition * +Instance::FindPartition(const char *name) +{ + for (auto &partition : partitions) + if (partition.name == name) + return &partition; + + return nullptr; +} + #ifdef ENABLE_DATABASE const Database & diff --git a/src/Instance.hxx b/src/Instance.hxx index 45e81cf81..dfc3a79e9 100644 --- a/src/Instance.hxx +++ b/src/Instance.hxx @@ -106,6 +106,13 @@ struct Instance final idle_monitor.OrMask(mask); } + /** + * Find a #Partition with the given name. Returns nullptr if + * no such partition was found. + */ + gcc_pure + Partition *FindPartition(const char *name); + #ifdef ENABLE_DATABASE /** * Returns the global #Database instance. May return nullptr diff --git a/src/command/PartitionCommands.cxx b/src/command/PartitionCommands.cxx index a125a3c43..5953437d2 100644 --- a/src/command/PartitionCommands.cxx +++ b/src/command/PartitionCommands.cxx @@ -58,13 +58,9 @@ IsValidPartitionName(const char *name) gcc_pure static bool -HasPartitionNamed(const Instance &instance, const char *name) +HasPartitionNamed(Instance &instance, const char *name) { - for (const auto &partition : instance.partitions) - if (partition.name == name) - return true; - - return false; + return instance.FindPartition(name) != nullptr; } CommandResult