db/*: use std::span instead of ConstBuffer

This commit is contained in:
Max Kellermann 2022-07-04 18:26:23 +02:00
parent 4fb8b45111
commit b9c9a5f1dd
9 changed files with 22 additions and 26 deletions

View File

@ -191,11 +191,11 @@ PrintSongUris(Response &r, Partition &partition,
}
static void
PrintUniqueTags(Response &r, ConstBuffer<TagType> tag_types,
PrintUniqueTags(Response &r, std::span<const TagType> tag_types,
const RecursiveMap<std::string> &map) noexcept
{
const char *const name = tag_item_names[tag_types.front()];
tag_types.pop_front();
tag_types = tag_types.subspan(1);
for (const auto &[key, tag] : map) {
r.Fmt(FMT_STRING("{}: {}\n"), name, key);
@ -207,7 +207,7 @@ PrintUniqueTags(Response &r, ConstBuffer<TagType> tag_types,
void
PrintUniqueTags(Response &r, Partition &partition,
ConstBuffer<TagType> tag_types,
std::span<const TagType> tag_types,
const SongFilter *filter)
{
const Database &db = partition.GetDatabaseOrThrow();

View File

@ -21,8 +21,8 @@
#define MPD_DB_PRINT_H
#include <cstdint>
#include <span>
template<typename T> struct ConstBuffer;
enum TagType : uint8_t;
class SongFilter;
struct DatabaseSelection;
@ -44,7 +44,7 @@ PrintSongUris(Response &r, Partition &partition,
void
PrintUniqueTags(Response &r, Partition &partition,
ConstBuffer<TagType> tag_types,
std::span<const TagType> tag_types,
const SongFilter *filter);
#endif

View File

@ -24,6 +24,7 @@
#include "tag/Type.h"
#include <chrono>
#include <span>
#include <string>
struct DatabasePlugin;
@ -31,7 +32,6 @@ struct DatabaseStats;
struct DatabaseSelection;
struct LightSong;
template<typename Key> class RecursiveMap;
template<typename T> struct ConstBuffer;
class Database {
const DatabasePlugin &plugin;
@ -111,7 +111,7 @@ public:
* Throws on error.
*/
virtual RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types) const = 0;
std::span<const TagType> tag_types) const = 0;
/**
* Throws on error.

View File

@ -21,18 +21,18 @@
#include "Interface.hxx"
#include "song/LightSong.hxx"
#include "tag/VisitFallback.hxx"
#include "util/ConstBuffer.hxx"
#include "util/RecursiveMap.hxx"
static void
CollectUniqueTags(RecursiveMap<std::string> &result,
const Tag &tag,
ConstBuffer<TagType> tag_types) noexcept
std::span<const TagType> tag_types) noexcept
{
if (tag_types.empty())
return;
const auto tag_type = tag_types.shift();
const auto tag_type = tag_types.front();
tag_types = tag_types.subspan(1);
VisitTagWithFallbackOrEmpty(tag, tag_type, [&result, &tag, tag_types](const char *value){
CollectUniqueTags(result[value], tag, tag_types);
@ -41,7 +41,7 @@ CollectUniqueTags(RecursiveMap<std::string> &result,
RecursiveMap<std::string>
CollectUniqueTags(const Database &db, const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types)
std::span<const TagType> tag_types)
{
RecursiveMap<std::string> result;

View File

@ -22,18 +22,18 @@
#include "tag/Type.h"
#include <span>
#include <string>
class Database;
struct DatabaseSelection;
template<typename Key> class RecursiveMap;
template<typename T> struct ConstBuffer;
/**
* Walk the database and collect unique tag values.
*/
RecursiveMap<std::string>
CollectUniqueTags(const Database &db, const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types);
std::span<const TagType> tag_types);
#endif

View File

@ -37,7 +37,6 @@
#include "tag/Builder.hxx"
#include "tag/Tag.hxx"
#include "tag/ParseName.hxx"
#include "util/ConstBuffer.hxx"
#include "util/RecursiveMap.hxx"
#include "util/ScopeExit.hxx"
#include "util/RuntimeError.hxx"
@ -136,7 +135,7 @@ public:
VisitPlaylist visit_playlist) const override;
RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types) const override;
std::span<const TagType> tag_types) const override;
DatabaseStats GetStats(const DatabaseSelection &selection) const override;
@ -440,13 +439,13 @@ SendGroup(mpd_connection *connection, TagType group)
}
static bool
SendGroup(mpd_connection *connection, ConstBuffer<TagType> group)
SendGroup(mpd_connection *connection, std::span<const TagType> group)
{
while (!group.empty()) {
if (!SendGroup(connection, group.back()))
return false;
group.pop_back();
group = group.first(group.size() - 1);
}
return true;
@ -1010,7 +1009,7 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
RecursiveMap<std::string>
ProxyDatabase::CollectUniqueTags(const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types) const
std::span<const TagType> tag_types) const
try {
// TODO: eliminate the const_cast
const_cast<ProxyDatabase *>(this)->EnsureConnected();
@ -1019,8 +1018,7 @@ try {
if (tag_type2 == MPD_TAG_COUNT)
throw std::runtime_error("Unsupported tag");
auto group = tag_types;
group.pop_back();
const auto group = tag_types.first(tag_types.size() - 1);
if (!mpd_search_db_tags(connection, tag_type2) ||
!SendConstraints(connection, selection, selection.window) ||

View File

@ -41,7 +41,6 @@
#include "fs/FileSystem.hxx"
#include "util/CharUtil.hxx"
#include "util/Domain.hxx"
#include "util/ConstBuffer.hxx"
#include "util/RecursiveMap.hxx"
#include "Log.hxx"
@ -334,7 +333,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
RecursiveMap<std::string>
SimpleDatabase::CollectUniqueTags(const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types) const
std::span<const TagType> tag_types) const
{
return ::CollectUniqueTags(*this, selection, tag_types);
}

View File

@ -126,7 +126,7 @@ public:
VisitPlaylist visit_playlist) const override;
RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types) const override;
std::span<const TagType> tag_types) const override;
DatabaseStats GetStats(const DatabaseSelection &selection) const override;

View File

@ -36,7 +36,6 @@
#include "db/Stats.hxx"
#include "tag/Table.hxx"
#include "fs/Traits.hxx"
#include "util/ConstBuffer.hxx"
#include "util/RecursiveMap.hxx"
#include "util/SplitString.hxx"
#include "config/Block.hxx"
@ -101,7 +100,7 @@ public:
VisitPlaylist visit_playlist) const override;
[[nodiscard]] RecursiveMap<std::string> CollectUniqueTags(const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types) const override;
std::span<const TagType> tag_types) const override;
[[nodiscard]] DatabaseStats GetStats(const DatabaseSelection &selection) const override;
@ -629,7 +628,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
RecursiveMap<std::string>
UpnpDatabase::CollectUniqueTags(const DatabaseSelection &selection,
ConstBuffer<TagType> tag_types) const
std::span<const TagType> tag_types) const
{
return ::CollectUniqueTags(*this, selection, tag_types);
}