• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

afxres / binary-cxx / 39976307313

23 Oct 2026 03:03PM UTC coverage: 99.257% (-0.1%) from 99.36%
39976307313

push

github

afxres
Fix performance issues for container converter and named object converter decode method

45 of 45 new or added lines in 5 files covered. (100.0%)

1 existing line in 1 file now uncovered.

935 of 942 relevant lines covered (99.26%)

113.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/code/binary/include/binary/components/NamedObjectConverter.hpp
1
#ifndef BINARY_COMPONENTS_NAMEDOBJECTCONVERTER_HPP
2
#define BINARY_COMPONENTS_NAMEDOBJECTCONVERTER_HPP
3

4
#include <cassert>
5
#include <span>
6

7
#include "binary/Converter.hpp"
8
#include "binary/ConverterExtensions.hpp"
9
#include "binary/components/NamedObjectDecoder.hpp"
10
#include "binary/internal/Define.hpp"
11

12
#if defined(_MSC_VER)
13
#include <malloc.h>
14
#define BINARY_NAMED_OBJECT_ALLOCA _alloca
15
#elif defined(__GNUC__)
16
#define BINARY_NAMED_OBJECT_ALLOCA __builtin_alloca
17
#endif
18

19
namespace binary::components {
20
template <typename T>
21
class NamedObjectConverter : public Converter<T> {
22
public:
23
    using EncodeFunction = std::function<void(Allocator&, const T&)>;
24
    using DecodeFunction = std::function<void(T&, std::span<const std::byte>)>;
25

26
    struct MemberInfo {
27
        bool IsOptional = false;
28
        std::string Name;
29
        std::vector<std::byte> Header;
30
        EncodeFunction EncodeWithLengthPrefix;
31
        DecodeFunction Decode;
32
    };
33

34
    explicit NamedObjectConverter(std::vector<MemberInfo>&& record)
23 ✔
35
        : record(std::move(record)) {
23 ✔
36
        for (const auto& info : this->record) {
67 ✔
37
            this->names.emplace_back(info.Name);
44 ✔
38
            this->headers.emplace_back(info.Header);
44 ✔
39
            this->optional.emplace_back(info.IsOptional);
44 ✔
40
        }
41
        this->decoder = std::make_unique<NamedObjectDecoder>(this->headers, this->names, this->optional);
23 ✔
42
    }
33 ✔
43

44
    BINARY_DEFINE_OVERRIDE_ENCODE_METHOD(T) {
11 ✔
45
        const auto& headers = this->headers;
11 ✔
46
        const auto& record = this->record;
11 ✔
47
        for (size_t i = 0; i < record.size(); i++) {
31 ✔
48
            EncodeWithLengthPrefix(allocator, headers.at(i));
20 ✔
49
            record.at(i).EncodeWithLengthPrefix(allocator, item);
20 ✔
50
        }
51
    }
11 ✔
52

53
    BINARY_DEFINE_OVERRIDE_DECODE_METHOD(T) {
16 ✔
54
        const auto& record = this->record;
16 ✔
55
        const auto length = record.size();
16 ✔
56
        auto* memory = static_cast<std::span<const std::byte>*>(BINARY_NAMED_OBJECT_ALLOCA(sizeof(std::span<const std::byte>) * length));
16 ✔
57
        const std::span<std::span<const std::byte>> slices(memory, length);
16 ✔
58
        this->decoder->Invoke(span, slices);
16 ✔
59

60
        T result{};
12 ✔
61
        for (size_t i = 0; i < length; i++) {
33 ✔
62
            const auto& intent = slices[i];
21 ✔
63
            assert(intent.data() != nullptr || this->optional.at(i));
21 ✔
64
            if (intent.data() != nullptr) {
21 ✔
65
                record.at(i).Decode(result, intent);
17 ✔
66
            }
67
        }
68
        return result;
23 ✔
UNCOV
69
    }
×
70

71
private:
72
    std::vector<uint8_t> optional;
73
    std::vector<MemberInfo> record;
74
    std::vector<std::string> names;
75
    std::vector<std::vector<std::byte>> headers;
76
    std::unique_ptr<NamedObjectDecoder> decoder;
77
};
78
}
79

80
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc