Coverage Report

Created: 2025-12-12 07:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hermes/include/hermes/VM/SmallXString.h
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
8
//===----------------------------------------------------------------------===//
9
/// \file
10
/// Wrapper around llvh::SmallVector<> for easier u16 string construction.
11
//===----------------------------------------------------------------------===//
12
13
#ifndef HERMES_VM_SMALLXSTRING_H
14
#define HERMES_VM_SMALLXSTRING_H
15
16
#include "llvh/ADT/ArrayRef.h"
17
#include "llvh/ADT/SmallVector.h"
18
#include "llvh/ADT/StringRef.h"
19
20
namespace hermes {
21
namespace vm {
22
23
template <typename T, unsigned N>
24
class SmallXString : public llvh::SmallVector<T, N> {
25
  using Super = llvh::SmallVector<T, N>;
26
27
 public:
28
  /// Construct empty.
29
231k
  SmallXString() {}
hermes::vm::SmallXString<char16_t, 32u>::SmallXString()
Line
Count
Source
29
231k
  SmallXString() {}
hermes::vm::SmallXString<char16_t, 64u>::SmallXString()
Line
Count
Source
29
121
  SmallXString() {}
Unexecuted instantiation: hermes::vm::SmallXString<char16_t, 128u>::SmallXString()
hermes::vm::SmallXString<char16_t, 4u>::SmallXString()
Line
Count
Source
29
83
  SmallXString() {}
30
  /// Construct from ArrayRef.
31
  SmallXString(llvh::ArrayRef<T> ref) : Super(ref.begin(), ref.end()) {}
32
  /// Construct from zero-terminated string.
33
  SmallXString(const T *strz)
34
0
      : Super(strz, strz + std::char_traits<T>::length(strz)) {}
35
  /// Construct from StringRef.
36
  SmallXString(llvh::StringRef strRef)
37
113
      : Super(strRef.bytes_begin(), strRef.bytes_end()) {}
38
  /// Construct from a pair of iterators.
39
  template <typename It>
40
  SmallXString(It first, It end) : Super(first, end) {}
41
42
  /// Append an ArrayRef.
43
0
  SmallXString &append(llvh::ArrayRef<T> ref) {
44
0
    Super::append(ref.begin(), ref.end());
45
0
    return *this;
46
0
  }
47
48
  /// Append a zero-terminated string.
49
88
  SmallXString &append(const T *strz) {
50
88
    Super::append(strz, strz + std::char_traits<T>::length(strz));
51
88
    return *this;
52
88
  }
53
54
  /// Append a StringRef.
55
283
  SmallXString &append(llvh::StringRef strRef) {
56
283
    Super::append(strRef.bytes_begin(), strRef.bytes_end());
57
283
    return *this;
58
283
  }
hermes::vm::SmallXString<char16_t, 32u>::append(llvh::StringRef)
Line
Count
Source
55
123
  SmallXString &append(llvh::StringRef strRef) {
56
123
    Super::append(strRef.bytes_begin(), strRef.bytes_end());
57
123
    return *this;
58
123
  }
hermes::vm::SmallXString<char16_t, 64u>::append(llvh::StringRef)
Line
Count
Source
55
160
  SmallXString &append(llvh::StringRef strRef) {
56
160
    Super::append(strRef.bytes_begin(), strRef.bytes_end());
57
160
    return *this;
58
160
  }
59
60
  /// Append a single character.
61
305k
  SmallXString &append(T ch) {
62
305k
    Super::push_back(ch);
63
305k
    return *this;
64
305k
  }
65
66
  /// Append a single ASCII character.
67
80
  SmallXString &append(char ch) {
68
80
    Super::push_back((unsigned char)ch);
69
80
    return *this;
70
80
  }
71
72
  template <typename in_iter>
73
113
  SmallXString &append(in_iter start, in_iter end) {
74
113
    Super::append(start, end);
75
113
    return *this;
76
113
  }
77
78
958
  llvh::ArrayRef<T> arrayRef() const {
79
958
    return llvh::ArrayRef<T>(Super::begin(), Super::end());
80
958
  }
hermes::vm::SmallXString<char16_t, 32u>::arrayRef() const
Line
Count
Source
78
958
  llvh::ArrayRef<T> arrayRef() const {
79
958
    return llvh::ArrayRef<T>(Super::begin(), Super::end());
80
958
  }
Unexecuted instantiation: hermes::vm::SmallXString<char16_t, 64u>::arrayRef() const
81
};
82
83
template <unsigned N>
84
using SmallU16String = SmallXString<char16_t, N>;
85
86
} // namespace vm
87
} // namespace hermes
88
89
#endif // HERMES_VM_SMALLXSTRING_H