refactor: remove LimitedQueueSnapshot (#6606)
Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages/LimitedQueueSnapshot.hpp"
|
||||
|
||||
#include <boost/circular_buffer.hpp>
|
||||
|
||||
#include <cassert>
|
||||
@@ -318,22 +316,28 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] LimitedQueueSnapshot<T> getSnapshot() const
|
||||
[[nodiscard]] std::vector<T> getSnapshot() const
|
||||
{
|
||||
std::shared_lock lock(this->mutex_);
|
||||
return LimitedQueueSnapshot<T>(this->buffer_);
|
||||
return {this->buffer_.begin(), this->buffer_.end()};
|
||||
}
|
||||
|
||||
[[nodiscard]] LimitedQueueSnapshot<T> lastN(size_t nItems) const
|
||||
[[nodiscard]] std::vector<T> lastN(size_t nItems) const
|
||||
{
|
||||
std::shared_lock lock(this->mutex_);
|
||||
return LimitedQueueSnapshot<T>::lastN(this->buffer_, nItems);
|
||||
return {
|
||||
this->buffer_.end() - std::min(nItems, this->buffer_.size()),
|
||||
this->buffer_.end(),
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] LimitedQueueSnapshot<T> firstN(size_t nItems) const
|
||||
[[nodiscard]] std::vector<T> firstN(size_t nItems) const
|
||||
{
|
||||
std::shared_lock lock(this->mutex_);
|
||||
return LimitedQueueSnapshot<T>::firstN(this->buffer_, nItems);
|
||||
return {
|
||||
this->buffer_.begin(),
|
||||
this->buffer_.begin() + std::min(nItems, this->buffer_.size()),
|
||||
};
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/circular_buffer.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename T>
|
||||
class LimitedQueue;
|
||||
|
||||
template <typename T>
|
||||
class LimitedQueueSnapshot
|
||||
{
|
||||
private:
|
||||
friend class LimitedQueue<T>;
|
||||
|
||||
LimitedQueueSnapshot(const boost::circular_buffer<T> &buf)
|
||||
: buffer_(buf.begin(), buf.end())
|
||||
{
|
||||
}
|
||||
|
||||
static LimitedQueueSnapshot lastN(const boost::circular_buffer<T> &buf,
|
||||
size_t n)
|
||||
{
|
||||
return {buf.end() - std::min(n, buf.size()), buf.end()};
|
||||
}
|
||||
|
||||
static LimitedQueueSnapshot firstN(const boost::circular_buffer<T> &buf,
|
||||
size_t n)
|
||||
{
|
||||
return {buf.begin(), buf.begin() + std::min(n, buf.size())};
|
||||
}
|
||||
|
||||
template <typename It>
|
||||
LimitedQueueSnapshot(It begin, It end)
|
||||
: buffer_(std::move(begin), std::move(end))
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
LimitedQueueSnapshot() = default;
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return this->buffer_.size();
|
||||
}
|
||||
|
||||
const T &operator[](size_t index) const
|
||||
{
|
||||
return this->buffer_[index];
|
||||
}
|
||||
|
||||
auto begin() const
|
||||
{
|
||||
return this->buffer_.begin();
|
||||
}
|
||||
|
||||
auto end() const
|
||||
{
|
||||
return this->buffer_.end();
|
||||
}
|
||||
|
||||
auto rbegin() const
|
||||
{
|
||||
return this->buffer_.rbegin();
|
||||
}
|
||||
|
||||
auto rend() const
|
||||
{
|
||||
return this->buffer_.rend();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<T> buffer_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "messages/LimitedQueueSnapshot.hpp" // IWYU pragma: keep
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
@@ -115,7 +114,5 @@ void setSimilarityFlags(const MessagePtr &message, const T &messages)
|
||||
|
||||
template void setSimilarityFlags<std::vector<MessagePtr>>(
|
||||
const MessagePtr &msg, const std::vector<MessagePtr> &messages);
|
||||
template void setSimilarityFlags<LimitedQueueSnapshot<MessagePtr>>(
|
||||
const MessagePtr &msg, const LimitedQueueSnapshot<MessagePtr> &messages);
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user