Coverage Report

Created: 2025-12-31 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pdns/pdns/noinitvector.hh
Line
Count
Source
1
#pragma once
2
3
#include <cstdint>
4
#include <memory>
5
#include <new>
6
#include <utility>
7
#include <vector>
8
9
// based on boost::core::noinit_adaptor
10
// The goal is to avoid initialization of the content of a container,
11
// because setting several kB of uint8_t to 0 has a real cost if you
12
// do 100k times per second.
13
template<class Allocator>
14
struct noinit_adaptor: Allocator
15
{
16
  template<class U>
17
  struct rebind {
18
    typedef noinit_adaptor<typename std::allocator_traits<Allocator>::template
19
                           rebind_alloc<U> > other;
20
    };
21
22
1.14k
  noinit_adaptor(): Allocator() { }
23
24
  template<class U>
25
  noinit_adaptor(U&& u) noexcept : Allocator(std::forward<U>(u)) { }
26
27
  template<class U>
28
  noinit_adaptor(const noinit_adaptor<U>& u) noexcept : Allocator(static_cast<const U&>(u)) { }
29
30
  template<class U>
31
0
  void construct(U* p) {
32
0
    ::new((void*)p) U;
33
0
  }
34
35
  template<class U, class V, class... Args>
36
5.17M
  void construct(U* p, V&& v, Args&&... args) {
37
5.17M
    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
38
5.17M
  }
Unexecuted instantiation: void noinit_adaptor<std::__1::allocator<unsigned char> >::construct<unsigned char, unsigned char>(unsigned char*, unsigned char&&)
Unexecuted instantiation: void noinit_adaptor<std::__1::allocator<unsigned char> >::construct<unsigned char, char const&>(unsigned char*, char const&)
Unexecuted instantiation: void noinit_adaptor<std::__1::allocator<unsigned char> >::construct<unsigned char, unsigned char&>(unsigned char*, unsigned char&)
void noinit_adaptor<std::__1::allocator<unsigned char> >::construct<unsigned char, unsigned char const&>(unsigned char*, unsigned char const&)
Line
Count
Source
36
5.17M
  void construct(U* p, V&& v, Args&&... args) {
37
5.17M
    ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
38
5.17M
  }
39
40
  template<class U>
41
5.17M
  void destroy(U* p) {
42
5.17M
    p->~U();
43
5.17M
  }
44
};
45
46
template<class T, class U>
47
inline bool operator==(const noinit_adaptor<T>& lhs,
48
                       const noinit_adaptor<U>& rhs) noexcept
49
{
50
  return static_cast<const T&>(lhs) == static_cast<const U&>(rhs);
51
}
52
53
template<class T, class U>
54
inline bool operator!=(const noinit_adaptor<T>& lhs,
55
                       const noinit_adaptor<U>& rhs) noexcept
56
{
57
  return !(lhs == rhs);
58
}
59
60
template<class Allocator>
61
inline noinit_adaptor<Allocator> noinit_adapt(const Allocator& a) noexcept
62
{
63
  return noinit_adaptor<Allocator>(a);
64
}
65
66
template<class T> using NoInitVector = std::vector<T, noinit_adaptor<std::allocator<T>>>;
67
68
using PacketBuffer = NoInitVector<uint8_t>;