diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-09-26 13:36:07 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-09-26 13:36:07 +1000 |
| commit | 4d99d22e10a3cb2a421da1618c127128816613c9 (patch) | |
| tree | 527490a466348e5cf40cf10a8f3768aa5be4e7c1 /src/database/include | |
| parent | f6d06421090f88094aba76b72b04d614f54efafa (diff) | |
| download | tangara-fw-4d99d22e10a3cb2a421da1618c127128816613c9.tar.gz | |
std::string -> std::pmr::string in psram
Diffstat (limited to 'src/database/include')
| -rw-r--r-- | src/database/include/database.hpp | 22 | ||||
| -rw-r--r-- | src/database/include/file_gatherer.hpp | 8 | ||||
| -rw-r--r-- | src/database/include/index.hpp | 10 | ||||
| -rw-r--r-- | src/database/include/records.hpp | 8 | ||||
| -rw-r--r-- | src/database/include/tag_parser.hpp | 18 | ||||
| -rw-r--r-- | src/database/include/track.hpp | 29 |
6 files changed, 48 insertions, 47 deletions
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp index 00704a5f..98540f41 100644 --- a/src/database/include/database.hpp +++ b/src/database/include/database.hpp @@ -22,9 +22,9 @@ #include "leveldb/iterator.h" #include "leveldb/options.h" #include "leveldb/slice.h" +#include "memory_resource.hpp" #include "records.hpp" #include "result.hpp" -#include "shared_string.h" #include "tag_parser.hpp" #include "tasks.hpp" #include "track.hpp" @@ -33,8 +33,8 @@ namespace database { template <typename T> struct Continuation { - std::string prefix; - std::string start_key; + std::pmr::string prefix; + std::pmr::string start_key; bool forward; bool was_prev_forward; size_t page_size; @@ -70,17 +70,17 @@ class Result { class IndexRecord { public: explicit IndexRecord(const IndexKey&, - std::optional<shared_string>, + std::optional<std::pmr::string>, std::optional<TrackId>); - auto text() const -> std::optional<shared_string>; + auto text() const -> std::optional<std::pmr::string>; auto track() const -> std::optional<TrackId>; auto Expand(std::size_t) const -> std::optional<Continuation<IndexRecord>>; private: IndexKey key_; - std::optional<shared_string> override_text_; + std::optional<std::pmr::string> override_text_; std::optional<TrackId> track_; }; @@ -100,7 +100,7 @@ class Database { auto Update() -> std::future<void>; - auto GetTrackPath(TrackId id) -> std::future<std::optional<std::string>>; + auto GetTrackPath(TrackId id) -> std::future<std::optional<std::pmr::string>>; auto GetTrack(TrackId id) -> std::future<std::optional<Track>>; @@ -115,7 +115,7 @@ class Database { auto GetTracksByIndex(const IndexInfo& index, std::size_t page_size) -> std::future<Result<IndexRecord>*>; auto GetTracks(std::size_t page_size) -> std::future<Result<Track>*>; - auto GetDump(std::size_t page_size) -> std::future<Result<std::string>*>; + auto GetDump(std::size_t page_size) -> std::future<Result<std::pmr::string>*>; template <typename T> auto GetPage(Continuation<T>* c) -> std::future<Result<T>*>; @@ -167,8 +167,8 @@ auto Database::ParseRecord<Track>(const leveldb::Slice& key, const leveldb::Slice& val) -> std::optional<Track>; template <> -auto Database::ParseRecord<std::string>(const leveldb::Slice& key, - const leveldb::Slice& val) - -> std::optional<std::string>; +auto Database::ParseRecord<std::pmr::string>(const leveldb::Slice& key, + const leveldb::Slice& val) + -> std::optional<std::pmr::string>; } // namespace database diff --git a/src/database/include/file_gatherer.hpp b/src/database/include/file_gatherer.hpp index ff0a6ac2..133cf81a 100644 --- a/src/database/include/file_gatherer.hpp +++ b/src/database/include/file_gatherer.hpp @@ -19,15 +19,15 @@ class IFileGatherer { public: virtual ~IFileGatherer(){}; - virtual auto FindFiles(const std::string& root, - std::function<void(const std::string&)> cb) + virtual auto FindFiles(const std::pmr::string& root, + std::function<void(const std::pmr::string&)> cb) -> void = 0; }; class FileGathererImpl : public IFileGatherer { public: - virtual auto FindFiles(const std::string& root, - std::function<void(const std::string&)> cb) + virtual auto FindFiles(const std::pmr::string& root, + std::function<void(const std::pmr::string&)> cb) -> void override; }; diff --git a/src/database/include/index.hpp b/src/database/include/index.hpp index 17b40f5b..838eff31 100644 --- a/src/database/include/index.hpp +++ b/src/database/include/index.hpp @@ -17,7 +17,7 @@ #include "leveldb/slice.h" #include "leveldb/write_batch.h" -#include "shared_string.h" +#include "memory_resource.hpp" #include "track.hpp" namespace database { @@ -29,7 +29,7 @@ struct IndexInfo { IndexId id; // Localised, user-friendly description of this index. e.g. "Albums by Artist" // or "All Tracks". - std::string name; + std::pmr::string name; // Specifier for how this index breaks down the database. std::vector<Tag> components; }; @@ -51,7 +51,7 @@ struct IndexKey { // The filterable / selectable item that this key represents. "Jacqueline" for // kArtist, "My Cool Album" for kAlbum, etc. - std::optional<std::string> item; + std::optional<std::pmr::string> item; // If this is a leaf component, the track id for this record. // This could reasonably be the value for a record, but we keep it as a part // of the key to help with disambiguation. @@ -59,8 +59,8 @@ struct IndexKey { }; auto Index(const IndexInfo&, const Track&, leveldb::WriteBatch*) -> bool; -auto ExpandHeader(const IndexKey::Header&, const std::optional<std::string>&) - -> IndexKey::Header; +auto ExpandHeader(const IndexKey::Header&, + const std::optional<std::pmr::string>&) -> IndexKey::Header; // Predefined indexes // TODO(jacqueline): Make these defined at runtime! :) diff --git a/src/database/include/records.hpp b/src/database/include/records.hpp index 58f29b20..b144dece 100644 --- a/src/database/include/records.hpp +++ b/src/database/include/records.hpp @@ -16,7 +16,7 @@ #include "leveldb/slice.h" #include "index.hpp" -#include "shared_string.h" +#include "memory_resource.hpp" #include "track.hpp" namespace database { @@ -28,10 +28,10 @@ namespace database { */ class OwningSlice { public: - std::string data; + std::pmr::string data; leveldb::Slice slice; - explicit OwningSlice(std::string d); + explicit OwningSlice(std::pmr::string d); }; /* @@ -88,6 +88,6 @@ auto TrackIdToBytes(TrackId id) -> OwningSlice; * Converts a track id encoded via TrackIdToBytes back into a TrackId. May * return nullopt if parsing fails. */ -auto BytesToTrackId(const std::string& bytes) -> std::optional<TrackId>; +auto BytesToTrackId(cpp::span<const char> bytes) -> std::optional<TrackId>; } // namespace database diff --git a/src/database/include/tag_parser.hpp b/src/database/include/tag_parser.hpp index 85721357..d77967d8 100644 --- a/src/database/include/tag_parser.hpp +++ b/src/database/include/tag_parser.hpp @@ -16,24 +16,24 @@ namespace database { class ITagParser { public: virtual ~ITagParser() {} - virtual auto ReadAndParseTags(const std::string& path, TrackTags* out) + virtual auto ReadAndParseTags(const std::pmr::string& path, TrackTags* out) -> bool = 0; }; class GenericTagParser : public ITagParser { public: - auto ReadAndParseTags(const std::string& path, TrackTags* out) + auto ReadAndParseTags(const std::pmr::string& path, TrackTags* out) -> bool override; }; class TagParserImpl : public ITagParser { public: TagParserImpl(); - auto ReadAndParseTags(const std::string& path, TrackTags* out) + auto ReadAndParseTags(const std::pmr::string& path, TrackTags* out) -> bool override; private: - std::map<std::string, std::unique_ptr<ITagParser>> extension_to_parser_; + std::map<std::pmr::string, std::unique_ptr<ITagParser>> extension_to_parser_; GenericTagParser generic_parser_; /* @@ -41,16 +41,16 @@ class TagParserImpl : public ITagParser { * cache should be slightly larger than any page sizes in the UI. */ std::mutex cache_mutex_; - util::LruCache<16, std::string, TrackTags> cache_; + util::LruCache<16, std::pmr::string, TrackTags> cache_; - // We could also consider keeping caches of artist name -> shared_string and - // similar. This hasn't been done yet, as this isn't a common workload in any - // of our UI. + // We could also consider keeping caches of artist name -> std::pmr::string + // and similar. This hasn't been done yet, as this isn't a common workload in + // any of our UI. }; class OpusTagParser : public ITagParser { public: - auto ReadAndParseTags(const std::string& path, TrackTags* out) + auto ReadAndParseTags(const std::pmr::string& path, TrackTags* out) -> bool override; }; diff --git a/src/database/include/track.hpp b/src/database/include/track.hpp index 41f552d2..1c11ddea 100644 --- a/src/database/include/track.hpp +++ b/src/database/include/track.hpp @@ -16,7 +16,7 @@ #include <utility> #include "leveldb/db.h" -#include "shared_string.h" +#include "memory_resource.hpp" #include "span.hpp" namespace database { @@ -64,7 +64,8 @@ class TrackTags { auto encoding() const -> Container { return encoding_; }; auto encoding(Container e) -> void { encoding_ = e; }; - TrackTags() : encoding_(Container::kUnsupported) {} + TrackTags() + : encoding_(Container::kUnsupported), tags_(&memory::kSpiRamResource) {} std::optional<int> channels; std::optional<int> sample_rate; @@ -72,9 +73,9 @@ class TrackTags { std::optional<int> duration; - auto set(const Tag& key, const std::string& val) -> void; - auto at(const Tag& key) const -> std::optional<shared_string>; - auto operator[](const Tag& key) const -> std::optional<shared_string>; + auto set(const Tag& key, const std::pmr::string& val) -> void; + auto at(const Tag& key) const -> std::optional<std::pmr::string>; + auto operator[](const Tag& key) const -> std::optional<std::pmr::string>; /* * Returns a hash of the 'identifying' tags of this track. That is, a hash @@ -90,7 +91,7 @@ class TrackTags { private: Container encoding_; - std::unordered_map<Tag, shared_string> tags_; + std::pmr::unordered_map<Tag, std::pmr::string> tags_; }; /* @@ -113,33 +114,33 @@ class TrackTags { class TrackData { private: const TrackId id_; - const std::string filepath_; + const std::pmr::string filepath_; const uint64_t tags_hash_; const uint32_t play_count_; const bool is_tombstoned_; public: /* Constructor used when adding new tracks to the database. */ - TrackData(TrackId id, const std::string& path, uint64_t hash) + TrackData(TrackId id, const std::pmr::string& path, uint64_t hash) : id_(id), - filepath_(path), + filepath_(path, &memory::kSpiRamResource), tags_hash_(hash), play_count_(0), is_tombstoned_(false) {} TrackData(TrackId id, - const std::string& path, + const std::pmr::string& path, uint64_t hash, uint32_t play_count, bool is_tombstoned) : id_(id), - filepath_(path), + filepath_(path, &memory::kSpiRamResource), tags_hash_(hash), play_count_(play_count), is_tombstoned_(is_tombstoned) {} auto id() const -> TrackId { return id_; } - auto filepath() const -> std::string { return filepath_; } + auto filepath() const -> std::pmr::string { return filepath_; } auto play_count() const -> uint32_t { return play_count_; } auto tags_hash() const -> uint64_t { return tags_hash_; } auto is_tombstoned() const -> bool { return is_tombstoned_; } @@ -156,7 +157,7 @@ class TrackData { * Clears the tombstone bit of this track, and updates the path to reflect its * new location. */ - auto Exhume(const std::string& new_path) const -> TrackData; + auto Exhume(const std::pmr::string& new_path) const -> TrackData; bool operator==(const TrackData&) const = default; }; @@ -178,7 +179,7 @@ class Track { auto data() const -> const TrackData& { return data_; } auto tags() const -> const TrackTags& { return tags_; } - auto TitleOrFilename() const -> shared_string; + auto TitleOrFilename() const -> std::pmr::string; bool operator==(const Track&) const = default; Track operator=(const Track& other) const { return Track(other); } |
