Commit e48ea5f2 authored by Max Kellermann's avatar Max Kellermann

Instance: add method FindPartition()

parent a99bab93
...@@ -39,6 +39,16 @@ Instance::Instance() ...@@ -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 #ifdef ENABLE_DATABASE
const Database & const Database &
......
...@@ -106,6 +106,13 @@ struct Instance final ...@@ -106,6 +106,13 @@ struct Instance final
idle_monitor.OrMask(mask); 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 #ifdef ENABLE_DATABASE
/** /**
* Returns the global #Database instance. May return nullptr * Returns the global #Database instance. May return nullptr
......
...@@ -58,13 +58,9 @@ IsValidPartitionName(const char *name) ...@@ -58,13 +58,9 @@ IsValidPartitionName(const char *name)
gcc_pure gcc_pure
static bool static bool
HasPartitionNamed(const Instance &instance, const char *name) HasPartitionNamed(Instance &instance, const char *name)
{ {
for (const auto &partition : instance.partitions) return instance.FindPartition(name) != nullptr;
if (partition.name == name)
return true;
return false;
} }
CommandResult CommandResult
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment