mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-12 23:32:11 +02:00
Swap Boost.Container's small_vector out for LLVM's
This implementation misses a shrink to fit function, but reassigning the vector with a fresh one should be equivalent.
This commit is contained in:
@@ -26,11 +26,11 @@
|
||||
#ifdef __WINE__
|
||||
#include "../wine-host/asio-fix.h"
|
||||
#endif
|
||||
#include <llvm/small-vector.h>
|
||||
#include <asio/io_context.hpp>
|
||||
#include <asio/local/stream_protocol.hpp>
|
||||
#include <asio/read.hpp>
|
||||
#include <asio/write.hpp>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <ghc/filesystem.hpp>
|
||||
|
||||
#include "../bitsery/traits/small-vector.h"
|
||||
@@ -71,37 +71,35 @@ using InputAdapter =
|
||||
* this way.
|
||||
*/
|
||||
template <size_t N>
|
||||
using SerializationBuffer = boost::container::small_vector<uint8_t, N>;
|
||||
using SerializationBuffer = llvm::SmallVector<uint8_t, N>;
|
||||
|
||||
/**
|
||||
* The class `SerializationBuffer<N>` is derived from, so we can erase the
|
||||
* buffer's initial capacity from all functions that work with them.
|
||||
*/
|
||||
using SerializationBufferBase = boost::container::small_vector_base<uint8_t>;
|
||||
using SerializationBufferBase = llvm::SmallVectorImpl<uint8_t>;
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename PodType, typename Allocator>
|
||||
inline ASIO_MUTABLE_BUFFER buffer(
|
||||
boost::container::small_vector_base<PodType, Allocator>& data)
|
||||
// These are copied verbatim `asio::buffer(std::vector<PodType, Allocator>&,
|
||||
// std::size_t)`, since `llvm::SmallVector` is mostly compatible with the STL
|
||||
// vector.
|
||||
template <typename PodType>
|
||||
inline ASIO_MUTABLE_BUFFER buffer(llvm::SmallVectorImpl<PodType>& data)
|
||||
ASIO_NOEXCEPT {
|
||||
return ASIO_MUTABLE_BUFFER(
|
||||
data.size() ? &data[0] : 0, data.size() * sizeof(PodType)
|
||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||
,
|
||||
detail::buffer_debug_check<typename boost::container::small_vector_base<
|
||||
PodType, Allocator>::iterator>(data.begin())
|
||||
detail::buffer_debug_check<
|
||||
typename llvm::SmallVectorImpl<PodType>::iterator>(data.begin())
|
||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||
);
|
||||
}
|
||||
|
||||
// These are copied verbatim `asio::buffer(std::vector<PodType,
|
||||
// Allocator>&, std::size_t)`, since `boost::container::small_vector` is
|
||||
// compatible with the STL vector.
|
||||
template <typename PodType, typename Allocator>
|
||||
inline ASIO_MUTABLE_BUFFER buffer(
|
||||
boost::container::small_vector_base<PodType, Allocator>& data,
|
||||
std::size_t max_size_in_bytes) ASIO_NOEXCEPT {
|
||||
template <typename PodType>
|
||||
inline ASIO_MUTABLE_BUFFER buffer(llvm::SmallVectorImpl<PodType>& data,
|
||||
std::size_t max_size_in_bytes) ASIO_NOEXCEPT {
|
||||
return ASIO_MUTABLE_BUFFER(
|
||||
data.size() ? &data[0] : 0,
|
||||
data.size() * sizeof(PodType) < max_size_in_bytes
|
||||
@@ -109,8 +107,8 @@ inline ASIO_MUTABLE_BUFFER buffer(
|
||||
: max_size_in_bytes
|
||||
#if defined(ASIO_ENABLE_BUFFER_DEBUGGING)
|
||||
,
|
||||
detail::buffer_debug_check<typename boost::container::small_vector_base<
|
||||
PodType, Allocator>::iterator>(data.begin())
|
||||
detail::buffer_debug_check<
|
||||
typename llvm::SmallVectorImpl<PodType>::iterator>(data.begin())
|
||||
#endif // ASIO_ENABLE_BUFFER_DEBUGGING
|
||||
);
|
||||
}
|
||||
|
||||
@@ -205,8 +205,8 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
|
||||
// from the socket, so we can override this for specific function calls
|
||||
// that potentially need to have their responses handled on the same
|
||||
// calling thread (i.e. mutual recursion).
|
||||
const Vst2EventResult response = this->send(
|
||||
[&](asio::local::stream_protocol::socket& socket) {
|
||||
const Vst2EventResult response =
|
||||
this->send([&](asio::local::stream_protocol::socket& socket) {
|
||||
return data_converter.send_event(socket, event,
|
||||
serialization_buffer());
|
||||
});
|
||||
@@ -294,7 +294,7 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
|
||||
* thread at all cost we'll just predefine a large buffer for every thread.
|
||||
*/
|
||||
SerializationBufferBase& serialization_buffer() {
|
||||
// This object also contains a `boost::container::small_vector` that has
|
||||
// This object also contains a `llvm::SmallVector` that has
|
||||
// capacity for a large-ish number of events so we don't have to
|
||||
// allocate under normal circumstances.
|
||||
constexpr size_t initial_events_size = sizeof(DynamicVstEvents);
|
||||
@@ -304,9 +304,13 @@ class Vst2EventHandler : public AdHocSocketHandler<Thread> {
|
||||
// when sending and receiving preset data. In such cases we do want to
|
||||
// reallocate the buffer on the next event to free up memory again. This
|
||||
// won't happen during audio processing.
|
||||
if (buffer.size() > initial_events_size) {
|
||||
buffer.resize(initial_events_size);
|
||||
buffer.shrink_to_fit();
|
||||
if (buffer.size() > initial_events_size * 2) {
|
||||
// NOTE: There's no `.shrink_to_fit()` implementation here, so we'll
|
||||
// just YOLO it and reinitialize the vector since we don't
|
||||
// need the old data
|
||||
buffer = SerializationBuffer<initial_events_size>{};
|
||||
// buffer.resize(initial_events_size);
|
||||
// buffer.shrink_to_fit();
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
Reference in New Issue
Block a user