Coverage Report

Created: 2025-10-31 09:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/node/deps/inspector_protocol/crdtp/span.h
Line
Count
Source
1
// Copyright 2019 The Chromium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#ifndef CRDTP_SPAN_H_
6
#define CRDTP_SPAN_H_
7
8
#include <cstdint>
9
#include <cstring>
10
#include <span>
11
#include <string>
12
#include <type_traits>
13
14
#include "export.h"
15
16
namespace crdtp {
17
18
// crdtp::span is a std::span which always holds const elements.
19
template <typename T>
20
using span = std::span<const T>;
21
22
template <size_t N>
23
0
constexpr span<char> MakeSpan(const char (&str)[N]) {
24
0
  return span<char>(str, N - 1);
25
0
}
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<9ul>(char const (&) [9ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<5ul>(char const (&) [5ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<6ul>(char const (&) [6ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<4ul>(char const (&) [4ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<10ul>(char const (&) [10ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<11ul>(char const (&) [11ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<19ul>(char const (&) [19ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<8ul>(char const (&) [8ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<23ul>(char const (&) [23ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<12ul>(char const (&) [12ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<13ul>(char const (&) [13ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<7ul>(char const (&) [7ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<18ul>(char const (&) [18ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<14ul>(char const (&) [14ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<22ul>(char const (&) [22ul])
Unexecuted instantiation: std::__1::span<char const, 18446744073709551615ul> crdtp::MakeSpan<16ul>(char const (&) [16ul])
26
27
template <size_t N>
28
constexpr span<uint8_t> SpanFrom(const char (&str)[N]) {
29
  return span<uint8_t>(reinterpret_cast<const uint8_t*>(str), N - 1);
30
}
31
32
0
constexpr inline span<uint8_t> SpanFrom(const char* str) {
33
0
  return str ? span<uint8_t>(reinterpret_cast<const uint8_t*>(str), strlen(str))
34
0
             : span<uint8_t>();
35
0
}
36
37
0
inline span<uint8_t> SpanFrom(const std::string& v) {
38
0
  return span<uint8_t>(reinterpret_cast<const uint8_t*>(v.data()), v.size());
39
0
}
40
41
// This SpanFrom routine works for std::vector<uint8_t> and
42
// std::vector<uint16_t>, but also for base::span<const uint8_t> in Chromium.
43
template <typename C,
44
          typename = std::enable_if_t<
45
              std::is_unsigned<typename C::value_type>{} &&
46
              std::is_member_function_pointer<decltype(&C::size)>{}>>
47
0
inline span<typename C::value_type> SpanFrom(const C& v) {
48
0
  return span<typename C::value_type>(v.data(), v.size());
49
0
}
50
51
// Less than / equality comparison functions for sorting / searching for byte
52
// spans.
53
CRDTP_EXPORT bool SpanLessThan(span<uint8_t> x, span<uint8_t> y) noexcept;
54
CRDTP_EXPORT bool SpanEquals(span<uint8_t> x, span<uint8_t> y) noexcept;
55
56
// Less than / equality comparison functions for sorting / searching for byte
57
// spans.
58
CRDTP_EXPORT bool SpanLessThan(span<char> x, span<char> y) noexcept;
59
CRDTP_EXPORT bool SpanEquals(span<char> x, span<char> y) noexcept;
60
61
struct SpanLt {
62
0
  bool operator()(span<uint8_t> l, span<uint8_t> r) const {
63
0
    return SpanLessThan(l, r);
64
0
  }
65
};
66
}  // namespace crdtp
67
68
#endif  // CRDTP_SPAN_H_