Skip to content

Commit ea55a81

Browse files
committed
Use array instead of vector for Simple* buffer
1 parent a25afd1 commit ea55a81

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Diff for: include/pisa/codec/simple16.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#pragma once
22
#include "FastPFor/headers/simple16.h"
33

4+
#include <array>
5+
46
namespace pisa {
57

68
struct simple16_block {
7-
static const uint64_t block_size = 128;
9+
static constexpr std::uint64_t block_size = 128;
810

911
static void
1012
encode(uint32_t const* in, uint32_t /* sum_of_values */, size_t n, std::vector<uint8_t>& out)
1113
{
1214
assert(n <= block_size);
1315
thread_local FastPForLib::Simple16<false> codec;
14-
thread_local std::vector<uint8_t> buf(2 * 8 * block_size);
16+
thread_local std::array<std::uint8_t, 2 * 8 * block_size> buf{};
1517
size_t out_len = buf.size();
1618
codec.encodeArray(in, n, reinterpret_cast<uint32_t*>(buf.data()), out_len);
1719
out_len *= 4;
@@ -23,14 +25,14 @@ struct simple16_block {
2325
{
2426
assert(n <= block_size);
2527
FastPForLib::Simple16<false> codec;
26-
std::vector<uint32_t> buf(2 * block_size);
28+
std::array<std::uint32_t, 2 * block_size> buf{};
2729

2830
auto const* ret = reinterpret_cast<uint8_t const*>(
2931
codec.decodeArray(reinterpret_cast<uint32_t const*>(in), 8 * n, buf.data(), n));
30-
for (size_t i = 0; i < n; ++i) {
31-
*out++ = buf[i];
32-
}
32+
33+
std::copy(buf.begin(), std::next(buf.begin(), n), out);
3334
return ret;
3435
}
3536
};
37+
3638
} // namespace pisa

Diff for: include/pisa/codec/simple8b.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#pragma once
22
#include "FastPFor/headers/simple8b.h"
33

4+
#include <array>
5+
46
namespace pisa {
57

68
struct simple8b_block {
7-
static const uint64_t block_size = 128;
9+
static constexpr std::uint64_t block_size = 128;
810

911
static void
1012
encode(uint32_t const* in, uint32_t /* sum_of_values */, size_t n, std::vector<uint8_t>& out)
1113
{
1214
assert(n <= block_size);
1315
thread_local FastPForLib::Simple8b<false> codec;
14-
thread_local std::vector<uint8_t> buf(2 * 8 * block_size);
16+
thread_local std::array<std::uint8_t, 2 * 8 * block_size> buf{};
1517
size_t out_len = buf.size();
1618
codec.encodeArray(in, n, reinterpret_cast<uint32_t*>(buf.data()), out_len);
1719
out_len *= 4;

0 commit comments

Comments
 (0)