mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 11:59:48 -04:00
feat: replace vector_byte_buffer with malloc_byte_buffer
The latter doesn't always explicitly initialize the allocated memory, which can help improve performance.
This commit is contained in:
parent
f6cf57b4be
commit
9996748134
@ -34,6 +34,7 @@ add_library(
|
|||||||
src/history.cpp
|
src/history.cpp
|
||||||
src/library_dependencies.cpp
|
src/library_dependencies.cpp
|
||||||
src/logger.cpp
|
src/logger.cpp
|
||||||
|
src/malloc_byte_buffer.cpp
|
||||||
src/mapped_byte_buffer.cpp
|
src/mapped_byte_buffer.cpp
|
||||||
src/mmap.cpp
|
src/mmap.cpp
|
||||||
src/option_map.cpp
|
src/option_map.cpp
|
||||||
@ -44,8 +45,6 @@ add_library(
|
|||||||
src/thread_pool.cpp
|
src/thread_pool.cpp
|
||||||
src/util.cpp
|
src/util.cpp
|
||||||
src/varint.cpp
|
src/varint.cpp
|
||||||
src/vector_byte_buffer.cpp
|
|
||||||
src/vector_byte_buffer_factory.cpp
|
|
||||||
src/xattr.cpp
|
src/xattr.cpp
|
||||||
|
|
||||||
src/internal/features.cpp
|
src/internal/features.cpp
|
||||||
@ -53,6 +52,7 @@ add_library(
|
|||||||
src/internal/fs_section.cpp
|
src/internal/fs_section.cpp
|
||||||
src/internal/fs_section_checker.cpp
|
src/internal/fs_section_checker.cpp
|
||||||
src/internal/glob_to_regex.cpp
|
src/internal/glob_to_regex.cpp
|
||||||
|
src/internal/malloc_buffer.cpp
|
||||||
src/internal/metadata_utils.cpp
|
src/internal/metadata_utils.cpp
|
||||||
src/internal/string_table.cpp
|
src/internal/string_table.cpp
|
||||||
src/internal/unicode_case_folding.cpp
|
src/internal/unicode_case_folding.cpp
|
||||||
|
@ -49,6 +49,12 @@ compare_spans(std::span<uint8_t const> lhs, std::span<uint8_t const> rhs);
|
|||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
|
||||||
|
class malloc_buffer;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class byte_buffer_interface {
|
class byte_buffer_interface {
|
||||||
public:
|
public:
|
||||||
virtual ~byte_buffer_interface() = default;
|
virtual ~byte_buffer_interface() = default;
|
||||||
@ -72,9 +78,7 @@ class mutable_byte_buffer_interface : public byte_buffer_interface {
|
|||||||
// that would reallocate the buffer will throw.
|
// that would reallocate the buffer will throw.
|
||||||
virtual void freeze_location() = 0;
|
virtual void freeze_location() = 0;
|
||||||
|
|
||||||
// TODO: See if we can do without this. This will *only* be implemented
|
virtual internal::malloc_buffer& raw_buffer() = 0;
|
||||||
// in the vector_byte_buffer, other implementations will throw.
|
|
||||||
virtual std::vector<uint8_t>& raw_vector() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class shared_byte_buffer {
|
class shared_byte_buffer {
|
||||||
@ -164,7 +168,7 @@ class mutable_byte_buffer {
|
|||||||
|
|
||||||
void freeze_location() { bb_->freeze_location(); }
|
void freeze_location() { bb_->freeze_location(); }
|
||||||
|
|
||||||
std::vector<uint8_t>& raw_vector() { return bb_->raw_vector(); }
|
internal::malloc_buffer& raw_buffer() { return bb_->raw_buffer(); }
|
||||||
|
|
||||||
void swap(mutable_byte_buffer& other) noexcept { std::swap(bb_, other.bb_); }
|
void swap(mutable_byte_buffer& other) noexcept { std::swap(bb_, other.bb_); }
|
||||||
|
|
||||||
|
93
include/dwarfs/internal/malloc_buffer.h
Normal file
93
include/dwarfs/internal/malloc_buffer.h
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/**
|
||||||
|
* \author Marcus Holland-Moritz (github@mhxnet.de)
|
||||||
|
* \copyright Copyright (c) Marcus Holland-Moritz
|
||||||
|
*
|
||||||
|
* This file is part of dwarfs.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the “Software”), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
|
namespace dwarfs::internal {
|
||||||
|
|
||||||
|
class malloc_buffer {
|
||||||
|
public:
|
||||||
|
using value_type = uint8_t;
|
||||||
|
|
||||||
|
malloc_buffer() = default;
|
||||||
|
malloc_buffer(size_t size);
|
||||||
|
malloc_buffer(void const* data, size_t size);
|
||||||
|
malloc_buffer(std::span<value_type const> data);
|
||||||
|
|
||||||
|
~malloc_buffer();
|
||||||
|
|
||||||
|
malloc_buffer(malloc_buffer&&) = default;
|
||||||
|
malloc_buffer& operator=(malloc_buffer&&) = default;
|
||||||
|
|
||||||
|
bool empty() const { return size_ == 0; }
|
||||||
|
|
||||||
|
size_t size() const { return size_; }
|
||||||
|
size_t capacity() const { return capacity_; }
|
||||||
|
|
||||||
|
value_type const* data() const { return data_; }
|
||||||
|
value_type* data() { return data_; }
|
||||||
|
|
||||||
|
void append(void const* data, size_t size) {
|
||||||
|
reserve(size_ + size);
|
||||||
|
copy(data_ + size_, data, size);
|
||||||
|
size_ += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear() { size_ = 0; }
|
||||||
|
|
||||||
|
void resize(size_t new_size) {
|
||||||
|
reserve(new_size);
|
||||||
|
size_ = new_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reserve(size_t new_capacity) {
|
||||||
|
if (new_capacity > capacity_) {
|
||||||
|
grow(new_capacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void shrink_to_fit();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void grow(size_t new_size);
|
||||||
|
void resize_buffer(size_t new_size);
|
||||||
|
static void copy(void* dest, void const* src, size_t size) {
|
||||||
|
// TODO: try std::copy or even something custom
|
||||||
|
std::memcpy(dest, src, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
value_type* data_{nullptr};
|
||||||
|
size_t size_{0};
|
||||||
|
size_t capacity_{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dwarfs::internal
|
@ -34,14 +34,19 @@
|
|||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
class vector_byte_buffer {
|
namespace internal {
|
||||||
|
class malloc_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
class malloc_byte_buffer {
|
||||||
public:
|
public:
|
||||||
static mutable_byte_buffer create();
|
static mutable_byte_buffer create();
|
||||||
static mutable_byte_buffer create(size_t size);
|
static mutable_byte_buffer create(size_t size);
|
||||||
|
static mutable_byte_buffer create_zeroed(size_t size);
|
||||||
static mutable_byte_buffer create_reserve(size_t size);
|
static mutable_byte_buffer create_reserve(size_t size);
|
||||||
static mutable_byte_buffer create(std::string_view data);
|
static mutable_byte_buffer create(std::string_view data);
|
||||||
static mutable_byte_buffer create(std::span<uint8_t const> data);
|
static mutable_byte_buffer create(std::span<uint8_t const> data);
|
||||||
static mutable_byte_buffer create(std::vector<uint8_t>&& data);
|
static mutable_byte_buffer create(internal::malloc_buffer&& data);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
class vector_byte_buffer_factory {
|
class malloc_byte_buffer_factory {
|
||||||
public:
|
public:
|
||||||
static byte_buffer_factory create();
|
static byte_buffer_factory create();
|
||||||
};
|
};
|
@ -29,7 +29,7 @@
|
|||||||
#include <dwarfs/block_decompressor.h>
|
#include <dwarfs/block_decompressor.h>
|
||||||
#include <dwarfs/decompressor_registry.h>
|
#include <dwarfs/decompressor_registry.h>
|
||||||
#include <dwarfs/fstypes.h>
|
#include <dwarfs/fstypes.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ shared_byte_buffer
|
|||||||
block_decompressor::decompress(compression_type type,
|
block_decompressor::decompress(compression_type type,
|
||||||
std::span<uint8_t const> data) {
|
std::span<uint8_t const> data) {
|
||||||
block_decompressor bd(type, data);
|
block_decompressor bd(type, data);
|
||||||
auto target = vector_byte_buffer::create_reserve(bd.uncompressed_size());
|
auto target = malloc_byte_buffer::create_reserve(bd.uncompressed_size());
|
||||||
bd.start_decompression(target);
|
bd.start_decompression(target);
|
||||||
bd.decompress_frame(bd.uncompressed_size());
|
bd.decompress_frame(bd.uncompressed_size());
|
||||||
return target.share();
|
return target.share();
|
||||||
|
@ -37,9 +37,9 @@
|
|||||||
#include <dwarfs/decompressor_registry.h>
|
#include <dwarfs/decompressor_registry.h>
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
#include <dwarfs/fstypes.h>
|
#include <dwarfs/fstypes.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/option_map.h>
|
#include <dwarfs/option_map.h>
|
||||||
#include <dwarfs/varint.h>
|
#include <dwarfs/varint.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ class brotli_block_compressor final : public block_compressor::impl {
|
|||||||
|
|
||||||
shared_byte_buffer compress(shared_byte_buffer const& data,
|
shared_byte_buffer compress(shared_byte_buffer const& data,
|
||||||
std::string const* /*metadata*/) const override {
|
std::string const* /*metadata*/) const override {
|
||||||
auto compressed = vector_byte_buffer::create(); // TODO: make configurable
|
auto compressed = malloc_byte_buffer::create(); // TODO: make configurable
|
||||||
compressed.resize(varint::max_size +
|
compressed.resize(varint::max_size +
|
||||||
::BrotliEncoderMaxCompressedSize(data.size()));
|
::BrotliEncoderMaxCompressedSize(data.size()));
|
||||||
size_t size_size = varint::encode(data.size(), compressed.data());
|
size_t size_size = varint::encode(data.size(), compressed.data());
|
||||||
|
@ -42,10 +42,10 @@
|
|||||||
#include <dwarfs/compressor_registry.h>
|
#include <dwarfs/compressor_registry.h>
|
||||||
#include <dwarfs/decompressor_registry.h>
|
#include <dwarfs/decompressor_registry.h>
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/option_map.h>
|
#include <dwarfs/option_map.h>
|
||||||
#include <dwarfs/pcm_sample_transformer.h>
|
#include <dwarfs/pcm_sample_transformer.h>
|
||||||
#include <dwarfs/varint.h>
|
#include <dwarfs/varint.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
|
|
||||||
#include <dwarfs/gen-cpp2/compression_types.h>
|
#include <dwarfs/gen-cpp2/compression_types.h>
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ class flac_block_compressor final : public block_compressor::impl {
|
|||||||
pcm_pad = pcm_sample_padding::Msb;
|
pcm_pad = pcm_sample_padding::Msb;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto compressed = vector_byte_buffer::create(); // TODO: make configurable
|
auto compressed = malloc_byte_buffer::create(); // TODO: make configurable
|
||||||
|
|
||||||
{
|
{
|
||||||
using namespace ::apache::thrift;
|
using namespace ::apache::thrift;
|
||||||
|
@ -36,8 +36,8 @@
|
|||||||
#include <dwarfs/decompressor_registry.h>
|
#include <dwarfs/decompressor_registry.h>
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
#include <dwarfs/fstypes.h>
|
#include <dwarfs/fstypes.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/option_map.h>
|
#include <dwarfs/option_map.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ class lz4_block_compressor final : public block_compressor::impl {
|
|||||||
|
|
||||||
shared_byte_buffer compress(shared_byte_buffer const& data,
|
shared_byte_buffer compress(shared_byte_buffer const& data,
|
||||||
std::string const* /*metadata*/) const override {
|
std::string const* /*metadata*/) const override {
|
||||||
auto compressed = vector_byte_buffer::create(); // TODO: make configurable
|
auto compressed = malloc_byte_buffer::create(); // TODO: make configurable
|
||||||
compressed.resize(sizeof(uint32_t) +
|
compressed.resize(sizeof(uint32_t) +
|
||||||
LZ4_compressBound(to<int>(data.size())));
|
LZ4_compressBound(to<int>(data.size())));
|
||||||
// TODO: this should have been a varint; also, if we ever support
|
// TODO: this should have been a varint; also, if we ever support
|
||||||
|
@ -42,10 +42,10 @@
|
|||||||
#include <dwarfs/decompressor_registry.h>
|
#include <dwarfs/decompressor_registry.h>
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
#include <dwarfs/fstypes.h>
|
#include <dwarfs/fstypes.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/option_map.h>
|
#include <dwarfs/option_map.h>
|
||||||
#include <dwarfs/sorted_array_map.h>
|
#include <dwarfs/sorted_array_map.h>
|
||||||
#include <dwarfs/types.h>
|
#include <dwarfs/types.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ lzma_block_compressor::compress(shared_byte_buffer const& data,
|
|||||||
|
|
||||||
lzma_action action = LZMA_FINISH;
|
lzma_action action = LZMA_FINISH;
|
||||||
|
|
||||||
auto compressed = vector_byte_buffer::create(); // TODO: make configurable
|
auto compressed = malloc_byte_buffer::create(); // TODO: make configurable
|
||||||
compressed.resize(data.size() - 1);
|
compressed.resize(data.size() - 1);
|
||||||
|
|
||||||
s.next_in = data.data();
|
s.next_in = data.data();
|
||||||
|
@ -38,9 +38,9 @@
|
|||||||
#include <dwarfs/compressor_registry.h>
|
#include <dwarfs/compressor_registry.h>
|
||||||
#include <dwarfs/decompressor_registry.h>
|
#include <dwarfs/decompressor_registry.h>
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/option_map.h>
|
#include <dwarfs/option_map.h>
|
||||||
#include <dwarfs/varint.h>
|
#include <dwarfs/varint.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
|
|
||||||
#include <dwarfs/gen-cpp2/compression_types.h>
|
#include <dwarfs/gen-cpp2/compression_types.h>
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ class ricepp_block_compressor final : public block_compressor::impl {
|
|||||||
.unused_lsb_count = static_cast<unsigned>(unused_lsb_count),
|
.unused_lsb_count = static_cast<unsigned>(unused_lsb_count),
|
||||||
});
|
});
|
||||||
|
|
||||||
auto compressed = vector_byte_buffer::create(); // TODO: make configurable
|
auto compressed = malloc_byte_buffer::create(); // TODO: make configurable
|
||||||
|
|
||||||
// TODO: see if we can resize just once...
|
// TODO: see if we can resize just once...
|
||||||
// TODO: maybe the mutable_byte_buffer interface can have .append()?
|
// TODO: maybe the mutable_byte_buffer interface can have .append()?
|
||||||
|
@ -36,8 +36,8 @@
|
|||||||
#include <dwarfs/decompressor_registry.h>
|
#include <dwarfs/decompressor_registry.h>
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
#include <dwarfs/fstypes.h>
|
#include <dwarfs/fstypes.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/option_map.h>
|
#include <dwarfs/option_map.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
#include <dwarfs/zstd_context_manager.h>
|
#include <dwarfs/zstd_context_manager.h>
|
||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
@ -101,7 +101,7 @@ class zstd_block_compressor final : public block_compressor::impl {
|
|||||||
shared_byte_buffer
|
shared_byte_buffer
|
||||||
zstd_block_compressor::compress(shared_byte_buffer const& data,
|
zstd_block_compressor::compress(shared_byte_buffer const& data,
|
||||||
std::string const* /*metadata*/) const {
|
std::string const* /*metadata*/) const {
|
||||||
auto compressed = vector_byte_buffer::create(); // TODO: make configurable
|
auto compressed = malloc_byte_buffer::create(); // TODO: make configurable
|
||||||
compressed.resize(ZSTD_compressBound(data.size()));
|
compressed.resize(ZSTD_compressBound(data.size()));
|
||||||
auto ctx = ctxmgr_->make_context();
|
auto ctx = ctxmgr_->make_context();
|
||||||
auto size = ZSTD_compressCCtx(ctx.get(), compressed.data(), compressed.size(),
|
auto size = ZSTD_compressCCtx(ctx.get(), compressed.data(), compressed.size(),
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include <dwarfs/config.h>
|
#include <dwarfs/config.h>
|
||||||
#include <dwarfs/history.h>
|
#include <dwarfs/history.h>
|
||||||
#include <dwarfs/library_dependencies.h>
|
#include <dwarfs/library_dependencies.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/version.h>
|
#include <dwarfs/version.h>
|
||||||
|
|
||||||
#include <dwarfs/gen-cpp2/history_types.h>
|
#include <dwarfs/gen-cpp2/history_types.h>
|
||||||
@ -91,7 +91,7 @@ size_t history::size() const { return history_->entries()->size(); }
|
|||||||
shared_byte_buffer history::serialize() const {
|
shared_byte_buffer history::serialize() const {
|
||||||
std::string buf;
|
std::string buf;
|
||||||
::apache::thrift::CompactSerializer::serialize(*history_, &buf);
|
::apache::thrift::CompactSerializer::serialize(*history_, &buf);
|
||||||
return vector_byte_buffer::create(buf).share();
|
return malloc_byte_buffer::create(buf).share();
|
||||||
}
|
}
|
||||||
|
|
||||||
void history::dump(std::ostream& os) const {
|
void history::dump(std::ostream& os) const {
|
||||||
|
85
src/internal/malloc_buffer.cpp
Normal file
85
src/internal/malloc_buffer.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||||
|
/**
|
||||||
|
* \author Marcus Holland-Moritz (github@mhxnet.de)
|
||||||
|
* \copyright Copyright (c) Marcus Holland-Moritz
|
||||||
|
*
|
||||||
|
* This file is part of dwarfs.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the “Software”), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
|
#include <dwarfs/internal/malloc_buffer.h>
|
||||||
|
|
||||||
|
namespace dwarfs::internal {
|
||||||
|
|
||||||
|
malloc_buffer::malloc_buffer(size_t size)
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
|
||||||
|
: data_{static_cast<value_type*>(std::malloc(size))}
|
||||||
|
, size_{size}
|
||||||
|
, capacity_{size} {
|
||||||
|
if (!data_) {
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
malloc_buffer::malloc_buffer(void const* data, size_t size)
|
||||||
|
: malloc_buffer(size) {
|
||||||
|
copy(data_, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
malloc_buffer::malloc_buffer(std::span<value_type const> data)
|
||||||
|
: malloc_buffer(data.size_bytes()) {
|
||||||
|
copy(data_, data.data(), data.size_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
malloc_buffer::~malloc_buffer() {
|
||||||
|
if (data_) {
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,cppcoreguidelines-owning-memory)
|
||||||
|
std::free(data_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void malloc_buffer::resize_buffer(size_t new_size) {
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc,cppcoreguidelines-owning-memory)
|
||||||
|
auto new_data = static_cast<value_type*>(std::realloc(data_, new_size));
|
||||||
|
if (!new_data) {
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
data_ = new_data;
|
||||||
|
capacity_ = new_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void malloc_buffer::grow(size_t new_size) {
|
||||||
|
assert(new_size > size_);
|
||||||
|
resize_buffer(new_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void malloc_buffer::shrink_to_fit() {
|
||||||
|
if (size_ < capacity_) {
|
||||||
|
resize_buffer(size_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dwarfs::internal
|
@ -27,27 +27,29 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <cstring>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
|
|
||||||
|
#include <dwarfs/internal/malloc_buffer.h>
|
||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class vector_byte_buffer_impl : public mutable_byte_buffer_interface {
|
class malloc_byte_buffer_impl : public mutable_byte_buffer_interface {
|
||||||
public:
|
public:
|
||||||
vector_byte_buffer_impl() = default;
|
malloc_byte_buffer_impl() = default;
|
||||||
explicit vector_byte_buffer_impl(size_t size)
|
explicit malloc_byte_buffer_impl(size_t size)
|
||||||
: data_(size) {}
|
: data_(size) {}
|
||||||
explicit vector_byte_buffer_impl(std::string_view data)
|
explicit malloc_byte_buffer_impl(std::string_view data)
|
||||||
: data_{data.begin(), data.end()} {}
|
: data_{data.data(), data.size()} {}
|
||||||
explicit vector_byte_buffer_impl(std::span<uint8_t const> data)
|
explicit malloc_byte_buffer_impl(std::span<uint8_t const> data)
|
||||||
: data_{data.begin(), data.end()} {}
|
: data_{data} {}
|
||||||
explicit vector_byte_buffer_impl(std::vector<uint8_t>&& data)
|
explicit malloc_byte_buffer_impl(internal::malloc_buffer&& data)
|
||||||
: data_{std::move(data)} {}
|
: data_{std::move(data)} {}
|
||||||
|
|
||||||
size_t size() const override { return data_.size(); }
|
size_t size() const override { return data_.size(); }
|
||||||
@ -92,7 +94,7 @@ class vector_byte_buffer_impl : public mutable_byte_buffer_interface {
|
|||||||
frozen_.store(true, std::memory_order_release);
|
frozen_.store(true, std::memory_order_release);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t>& raw_vector() override { return data_; }
|
internal::malloc_buffer& raw_buffer() override { return data_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void assert_not_frozen(std::string_view what) const {
|
void assert_not_frozen(std::string_view what) const {
|
||||||
@ -108,38 +110,44 @@ class vector_byte_buffer_impl : public mutable_byte_buffer_interface {
|
|||||||
|
|
||||||
bool frozen() const { return frozen_.load(std::memory_order_acquire); }
|
bool frozen() const { return frozen_.load(std::memory_order_acquire); }
|
||||||
|
|
||||||
std::vector<uint8_t> data_;
|
internal::malloc_buffer data_;
|
||||||
std::atomic<bool> frozen_{false};
|
std::atomic<bool> frozen_{false};
|
||||||
static_assert(std::atomic<bool>::is_always_lock_free);
|
static_assert(std::atomic<bool>::is_always_lock_free);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
mutable_byte_buffer vector_byte_buffer::create() {
|
mutable_byte_buffer malloc_byte_buffer::create() {
|
||||||
return mutable_byte_buffer{std::make_shared<vector_byte_buffer_impl>()};
|
return mutable_byte_buffer{std::make_shared<malloc_byte_buffer_impl>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
mutable_byte_buffer vector_byte_buffer::create(size_t size) {
|
mutable_byte_buffer malloc_byte_buffer::create(size_t size) {
|
||||||
return mutable_byte_buffer{std::make_shared<vector_byte_buffer_impl>(size)};
|
return mutable_byte_buffer{std::make_shared<malloc_byte_buffer_impl>(size)};
|
||||||
}
|
}
|
||||||
|
|
||||||
mutable_byte_buffer vector_byte_buffer::create_reserve(size_t size) {
|
mutable_byte_buffer malloc_byte_buffer::create_zeroed(size_t size) {
|
||||||
auto rv = std::make_shared<vector_byte_buffer_impl>();
|
auto buffer = std::make_shared<malloc_byte_buffer_impl>(size);
|
||||||
|
std::memset(buffer->mutable_data(), 0, size);
|
||||||
|
return mutable_byte_buffer{std::move(buffer)};
|
||||||
|
}
|
||||||
|
|
||||||
|
mutable_byte_buffer malloc_byte_buffer::create_reserve(size_t size) {
|
||||||
|
auto rv = std::make_shared<malloc_byte_buffer_impl>();
|
||||||
rv->reserve(size);
|
rv->reserve(size);
|
||||||
return mutable_byte_buffer{std::move(rv)};
|
return mutable_byte_buffer{std::move(rv)};
|
||||||
}
|
}
|
||||||
|
|
||||||
mutable_byte_buffer vector_byte_buffer::create(std::string_view data) {
|
mutable_byte_buffer malloc_byte_buffer::create(std::string_view data) {
|
||||||
return mutable_byte_buffer{std::make_shared<vector_byte_buffer_impl>(data)};
|
return mutable_byte_buffer{std::make_shared<malloc_byte_buffer_impl>(data)};
|
||||||
}
|
}
|
||||||
|
|
||||||
mutable_byte_buffer vector_byte_buffer::create(std::span<uint8_t const> data) {
|
mutable_byte_buffer malloc_byte_buffer::create(std::span<uint8_t const> data) {
|
||||||
return mutable_byte_buffer{std::make_shared<vector_byte_buffer_impl>(data)};
|
return mutable_byte_buffer{std::make_shared<malloc_byte_buffer_impl>(data)};
|
||||||
}
|
}
|
||||||
|
|
||||||
mutable_byte_buffer vector_byte_buffer::create(std::vector<uint8_t>&& data) {
|
mutable_byte_buffer malloc_byte_buffer::create(internal::malloc_buffer&& data) {
|
||||||
return mutable_byte_buffer{
|
return mutable_byte_buffer{
|
||||||
std::make_shared<vector_byte_buffer_impl>(std::move(data))};
|
std::make_shared<malloc_byte_buffer_impl>(std::move(data))};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
@ -26,25 +26,25 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/vector_byte_buffer_factory.h>
|
#include <dwarfs/malloc_byte_buffer_factory.h>
|
||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class vector_byte_buffer_factory_impl : public byte_buffer_factory_interface {
|
class malloc_byte_buffer_factory_impl : public byte_buffer_factory_interface {
|
||||||
public:
|
public:
|
||||||
mutable_byte_buffer create_mutable_fixed_reserve(size_t size) const override {
|
mutable_byte_buffer create_mutable_fixed_reserve(size_t size) const override {
|
||||||
return vector_byte_buffer::create_reserve(size);
|
return malloc_byte_buffer::create_reserve(size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
byte_buffer_factory vector_byte_buffer_factory::create() {
|
byte_buffer_factory malloc_byte_buffer_factory::create() {
|
||||||
return byte_buffer_factory{
|
return byte_buffer_factory{
|
||||||
std::make_shared<vector_byte_buffer_factory_impl>()};
|
std::make_shared<malloc_byte_buffer_factory_impl>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
@ -36,8 +36,8 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/reader/block_cache_byte_buffer_factory.h>
|
#include <dwarfs/reader/block_cache_byte_buffer_factory.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
|
|
||||||
namespace dwarfs::reader {
|
namespace dwarfs::reader {
|
||||||
|
|
||||||
@ -138,9 +138,9 @@ class mmap_byte_buffer_impl : public mutable_byte_buffer_interface {
|
|||||||
// always frozen
|
// always frozen
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t>& raw_vector() override {
|
internal::malloc_buffer& raw_buffer() override {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"operation not allowed on mmap buffer: raw_vector");
|
"operation not allowed on mmap buffer: raw_buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -163,7 +163,7 @@ class block_cache_byte_buffer_factory_impl
|
|||||||
if (mode_ == block_cache_allocation_mode::MMAP) {
|
if (mode_ == block_cache_allocation_mode::MMAP) {
|
||||||
return mutable_byte_buffer{std::make_shared<mmap_byte_buffer_impl>(size)};
|
return mutable_byte_buffer{std::make_shared<mmap_byte_buffer_impl>(size)};
|
||||||
}
|
}
|
||||||
return vector_byte_buffer::create_reserve(size);
|
return malloc_byte_buffer::create_reserve(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include <dwarfs/fstypes.h>
|
#include <dwarfs/fstypes.h>
|
||||||
#include <dwarfs/history.h>
|
#include <dwarfs/history.h>
|
||||||
#include <dwarfs/logger.h>
|
#include <dwarfs/logger.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/mapped_byte_buffer.h>
|
#include <dwarfs/mapped_byte_buffer.h>
|
||||||
#include <dwarfs/mmif.h>
|
#include <dwarfs/mmif.h>
|
||||||
#include <dwarfs/os_access.h>
|
#include <dwarfs/os_access.h>
|
||||||
@ -53,7 +54,6 @@
|
|||||||
#include <dwarfs/reader/filesystem_v2.h>
|
#include <dwarfs/reader/filesystem_v2.h>
|
||||||
#include <dwarfs/reader/fsinfo_options.h>
|
#include <dwarfs/reader/fsinfo_options.h>
|
||||||
#include <dwarfs/util.h>
|
#include <dwarfs/util.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
|
|
||||||
#include <dwarfs/internal/fs_section.h>
|
#include <dwarfs/internal/fs_section.h>
|
||||||
#include <dwarfs/internal/fs_section_checker.h>
|
#include <dwarfs/internal/fs_section_checker.h>
|
||||||
|
@ -40,9 +40,9 @@
|
|||||||
#include <dwarfs/checksum.h>
|
#include <dwarfs/checksum.h>
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
#include <dwarfs/logger.h>
|
#include <dwarfs/logger.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/thread_pool.h>
|
#include <dwarfs/thread_pool.h>
|
||||||
#include <dwarfs/util.h>
|
#include <dwarfs/util.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
#include <dwarfs/writer/compression_metadata_requirements.h>
|
#include <dwarfs/writer/compression_metadata_requirements.h>
|
||||||
#include <dwarfs/writer/filesystem_writer.h>
|
#include <dwarfs/writer/filesystem_writer.h>
|
||||||
#include <dwarfs/writer/filesystem_writer_options.h>
|
#include <dwarfs/writer/filesystem_writer_options.h>
|
||||||
@ -395,7 +395,7 @@ class rewritten_fsblock : public fsblock::impl {
|
|||||||
{
|
{
|
||||||
// TODO: we don't have to do this for uncompressed blocks
|
// TODO: we don't have to do this for uncompressed blocks
|
||||||
block_decompressor bd(data_comp_type_, data_);
|
block_decompressor bd(data_comp_type_, data_);
|
||||||
auto buffer = bd.start_decompression(vector_byte_buffer::create());
|
auto buffer = bd.start_decompression(malloc_byte_buffer::create());
|
||||||
bd.decompress_frame(bd.uncompressed_size());
|
bd.decompress_frame(bd.uncompressed_size());
|
||||||
|
|
||||||
if (!meta) {
|
if (!meta) {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include <thrift/lib/cpp2/frozen/FrozenUtil.h>
|
#include <thrift/lib/cpp2/frozen/FrozenUtil.h>
|
||||||
#include <thrift/lib/cpp2/protocol/Serializer.h>
|
#include <thrift/lib/cpp2/protocol/Serializer.h>
|
||||||
|
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
|
|
||||||
#include <dwarfs/writer/internal/metadata_freezer.h>
|
#include <dwarfs/writer/internal/metadata_freezer.h>
|
||||||
|
|
||||||
@ -47,9 +47,9 @@ std::pair<shared_byte_buffer, shared_byte_buffer> freeze_to_buffer(T const& x) {
|
|||||||
std::string schema;
|
std::string schema;
|
||||||
serializeRootLayout(layout, schema);
|
serializeRootLayout(layout, schema);
|
||||||
|
|
||||||
auto schema_buffer = vector_byte_buffer::create(schema);
|
auto schema_buffer = malloc_byte_buffer::create(schema);
|
||||||
|
|
||||||
auto data_buffer = vector_byte_buffer::create(content_size);
|
auto data_buffer = malloc_byte_buffer::create_zeroed(content_size);
|
||||||
|
|
||||||
folly::MutableByteRange content_range(data_buffer.data(), data_buffer.size());
|
folly::MutableByteRange content_range(data_buffer.data(), data_buffer.size());
|
||||||
ByteRangeFreezer::freeze(layout, x, content_range);
|
ByteRangeFreezer::freeze(layout, x, content_range);
|
||||||
|
@ -47,11 +47,12 @@
|
|||||||
#include <dwarfs/compression_constraints.h>
|
#include <dwarfs/compression_constraints.h>
|
||||||
#include <dwarfs/error.h>
|
#include <dwarfs/error.h>
|
||||||
#include <dwarfs/logger.h>
|
#include <dwarfs/logger.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/util.h>
|
#include <dwarfs/util.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
#include <dwarfs/writer/segmenter.h>
|
#include <dwarfs/writer/segmenter.h>
|
||||||
#include <dwarfs/writer/writer_progress.h>
|
#include <dwarfs/writer/writer_progress.h>
|
||||||
|
|
||||||
|
#include <dwarfs/internal/malloc_buffer.h>
|
||||||
#include <dwarfs/writer/internal/block_manager.h>
|
#include <dwarfs/writer/internal/block_manager.h>
|
||||||
#include <dwarfs/writer/internal/chunkable.h>
|
#include <dwarfs/writer/internal/chunkable.h>
|
||||||
#include <dwarfs/writer/internal/cyclic_hash.h>
|
#include <dwarfs/writer/internal/cyclic_hash.h>
|
||||||
@ -559,13 +560,10 @@ class basic_granular_container_adapter : private GranularityPolicy {
|
|||||||
T& v_;
|
T& v_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename GranularityPolicy>
|
|
||||||
using granular_vector_adapter =
|
|
||||||
basic_granular_container_adapter<std::vector<T>, GranularityPolicy>;
|
|
||||||
|
|
||||||
template <typename GranularityPolicy>
|
template <typename GranularityPolicy>
|
||||||
using granular_byte_buffer_adapter =
|
using granular_buffer_adapter =
|
||||||
basic_granular_container_adapter<mutable_byte_buffer, GranularityPolicy>;
|
basic_granular_container_adapter<dwarfs::internal::malloc_buffer,
|
||||||
|
GranularityPolicy>;
|
||||||
|
|
||||||
template <typename LoggerPolicy, typename GranularityPolicy>
|
template <typename LoggerPolicy, typename GranularityPolicy>
|
||||||
class active_block : private GranularityPolicy {
|
class active_block : private GranularityPolicy {
|
||||||
@ -590,7 +588,7 @@ class active_block : private GranularityPolicy {
|
|||||||
, filter_(bloom_filter_size)
|
, filter_(bloom_filter_size)
|
||||||
, repseqmap_{repseqmap}
|
, repseqmap_{repseqmap}
|
||||||
, repeating_collisions_{repcoll}
|
, repeating_collisions_{repcoll}
|
||||||
, data_{vector_byte_buffer::create()} {
|
, data_{malloc_byte_buffer::create()} {
|
||||||
DWARFS_CHECK((window_step & window_step_mask_) == 0,
|
DWARFS_CHECK((window_step & window_step_mask_) == 0,
|
||||||
"window step size not a power of two");
|
"window step size not a power of two");
|
||||||
data_.reserve(this->frames_to_bytes(capacity_in_frames_));
|
data_.reserve(this->frames_to_bytes(capacity_in_frames_));
|
||||||
@ -894,8 +892,8 @@ active_block<LoggerPolicy, GranularityPolicy>::append_bytes(
|
|||||||
auto src = this->template create<
|
auto src = this->template create<
|
||||||
granular_span_adapter<uint8_t const, GranularityPolicy>>(data);
|
granular_span_adapter<uint8_t const, GranularityPolicy>>(data);
|
||||||
|
|
||||||
auto v = this->template create<
|
auto v = this->template create<granular_buffer_adapter<GranularityPolicy>>(
|
||||||
granular_vector_adapter<uint8_t, GranularityPolicy>>(data_.raw_vector());
|
data_.raw_buffer());
|
||||||
|
|
||||||
// TODO: this works in theory, but slows down the segmenter by almost 10%
|
// TODO: this works in theory, but slows down the segmenter by almost 10%
|
||||||
// auto v = this->template create<
|
// auto v = this->template create<
|
||||||
@ -936,9 +934,8 @@ template <typename LoggerPolicy, typename GranularityPolicy>
|
|||||||
void segment_match<LoggerPolicy, GranularityPolicy>::verify_and_extend(
|
void segment_match<LoggerPolicy, GranularityPolicy>::verify_and_extend(
|
||||||
granular_span_adapter<uint8_t const, GranularityPolicy> const& data,
|
granular_span_adapter<uint8_t const, GranularityPolicy> const& data,
|
||||||
size_t pos, size_t len, size_t begin, size_t end) {
|
size_t pos, size_t len, size_t begin, size_t end) {
|
||||||
auto v = this->template create<
|
auto v = this->template create<granular_buffer_adapter<GranularityPolicy>>(
|
||||||
granular_vector_adapter<uint8_t, GranularityPolicy>>(
|
block_->data().raw_buffer());
|
||||||
block_->data().raw_vector());
|
|
||||||
|
|
||||||
// First, check if the regions actually match
|
// First, check if the regions actually match
|
||||||
if (v.compare(offset_, data.subspan(pos, len)) == 0) {
|
if (v.compare(offset_, data.subspan(pos, len)) == 0) {
|
||||||
|
@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
#include <dwarfs/block_compressor.h>
|
#include <dwarfs/block_compressor.h>
|
||||||
#include <dwarfs/block_decompressor.h>
|
#include <dwarfs/block_decompressor.h>
|
||||||
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
#include <dwarfs/pcm_sample_transformer.h>
|
#include <dwarfs/pcm_sample_transformer.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
|
||||||
|
|
||||||
using namespace dwarfs;
|
using namespace dwarfs;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ make_test_data(int channels, int samples, int bytes, int bits,
|
|||||||
make_sine<T>(bits, samples, 3.1 * ((599 * (c + 1)) % 256)));
|
make_sine<T>(bits, samples, 3.1 * ((599 * (c + 1)) % 256)));
|
||||||
}
|
}
|
||||||
auto muxed = multiplex(data);
|
auto muxed = multiplex(data);
|
||||||
auto out = vector_byte_buffer::create();
|
auto out = malloc_byte_buffer::create();
|
||||||
out.resize(bytes * channels * samples);
|
out.resize(bytes * channels * samples);
|
||||||
pcm_sample_transformer<T> xfm(end, sig, pad, bytes, bits);
|
pcm_sample_transformer<T> xfm(end, sig, pad, bytes, bits);
|
||||||
xfm.pack(out.span(), muxed);
|
xfm.pack(out.span(), muxed);
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
#include <dwarfs/block_compressor.h>
|
#include <dwarfs/block_compressor.h>
|
||||||
#include <dwarfs/block_decompressor.h>
|
#include <dwarfs/block_decompressor.h>
|
||||||
#include <dwarfs/vector_byte_buffer.h>
|
#include <dwarfs/malloc_byte_buffer.h>
|
||||||
|
|
||||||
using namespace dwarfs;
|
using namespace dwarfs;
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ shared_byte_buffer make_test_data(int components, int pixels, int unused_lsb) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto out = vector_byte_buffer::create();
|
auto out = malloc_byte_buffer::create();
|
||||||
out.resize(tmp.size() * sizeof(ValueType));
|
out.resize(tmp.size() * sizeof(ValueType));
|
||||||
std::memcpy(out.data(), tmp.data(), out.size());
|
std::memcpy(out.data(), tmp.data(), out.size());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user