Skip to content

Commit ae79c90

Browse files
committed
fix: clang-tidy warwnings
1 parent 088179e commit ae79c90

6 files changed

Lines changed: 44 additions & 27 deletions

File tree

packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioParamHostObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AudioParamHostObject : public JsiHostObject {
3939
friend class AudioNodeHostObject;
4040

4141
std::shared_ptr<AudioParam> param_;
42-
AutomationControlQueue controlQueue_ = AutomationControlQueue();
42+
AutomationControlQueue controlQueue_;
4343
float defaultValue_;
4444
float minValue_;
4545
float maxValue_;

packages/react-native-audio-api/common/cpp/audioapi/core/utils/Constants.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <cmath>
4+
#include <cstddef>
45
#include <limits>
56
#include <new>
67
#include <numbers>
@@ -44,4 +45,7 @@ using std::hardware_destructive_interference_size;
4445
constexpr std::size_t hardware_constructive_interference_size = 64;
4546
constexpr std::size_t hardware_destructive_interference_size = 64;
4647
#endif
48+
49+
// audio param
50+
inline constexpr size_t AUDIO_PARAM_MAX_QUEUED_EVENTS = 32;
4751
} // namespace audioapi

packages/react-native-audio-api/common/cpp/audioapi/core/utils/automation/AutomationControlQueue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Result<NoneType, std::string> AutomationControlQueue::checkCurveExclusion(
1212
const AutomationEvent &event) {
1313
if (event.getType() == AutomationEventType::SET_VALUE_CURVE) {
1414
const auto *conflict = findEventInInterval(event.getStartTime(), event.getEndTime());
15-
if (conflict) {
15+
if (conflict != nullptr) {
1616
return Err(
1717
std::format(
1818
"Cannot schedule curve event from time {} to {} because it conflicts with an existing event of type {} at time {}.",
@@ -23,7 +23,7 @@ Result<NoneType, std::string> AutomationControlQueue::checkCurveExclusion(
2323
}
2424
} else {
2525
const auto *conflict = findEventAtTime(event.getAutomationEventTime());
26-
if (conflict && conflict->getType() == AutomationEventType::SET_VALUE_CURVE) {
26+
if ((conflict != nullptr) && conflict->getType() == AutomationEventType::SET_VALUE_CURVE) {
2727
return Err(
2828
std::format(
2929
"Cannot schedule event of type {} at time {} because it conflicts with an existing curve event from time {} to {}.",

packages/react-native-audio-api/common/cpp/audioapi/core/utils/automation/AutomationControlQueue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class AutomationControlQueue : public AutomationQueueBase<AutomationEvent> {
2424
void cancelScheduledValues(double cancelTime) override;
2525

2626
private:
27-
const AutomationEvent *findEventAtTime(double time) const;
28-
const AutomationEvent *findEventInInterval(double startTime, double endTime) const;
27+
[[nodiscard]] const AutomationEvent *findEventAtTime(double time) const;
28+
[[nodiscard]] const AutomationEvent *findEventInInterval(double startTime, double endTime) const;
2929
};
3030

3131
} // namespace audioapi

packages/react-native-audio-api/common/cpp/audioapi/core/utils/automation/AutomationQueueBase.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#pragma once
22

33
#include <utility>
4+
#include "audioapi/core/utils/Constants.h"
45
#include "audioapi/utils/BoundedPriorityQueue.hpp"
56

67
namespace audioapi {
78

89
template <typename TEvent>
910
class AutomationQueueBase {
1011
public:
12+
AutomationQueueBase() = default;
13+
AutomationQueueBase(const AutomationQueueBase &) = delete;
14+
AutomationQueueBase &operator=(const AutomationQueueBase &) = delete;
15+
AutomationQueueBase(AutomationQueueBase &&) noexcept = delete;
16+
AutomationQueueBase &operator=(AutomationQueueBase &&) noexcept = delete;
1117
virtual ~AutomationQueueBase() = default;
1218

1319
/// @brief Cancel scheduled parameter changes at or after the given time.
@@ -23,12 +29,12 @@ class AutomationQueueBase {
2329
}
2430

2531
/// @brief Check if the event queue is empty.
26-
[[nodiscard]] inline bool isEmpty() const noexcept {
32+
[[nodiscard]] bool isEmpty() const noexcept {
2733
return eventQueue_.isEmpty();
2834
}
2935

3036
/// @brief Check if the event queue is full.
31-
[[nodiscard]] inline bool isFull() const noexcept {
37+
[[nodiscard]] bool isFull() const noexcept {
3238
return eventQueue_.isFull();
3339
}
3440

@@ -51,7 +57,7 @@ class AutomationQueueBase {
5157
}
5258
};
5359

54-
BoundedPriorityQueue<TEvent, 32, EventComparator> eventQueue_;
60+
BoundedPriorityQueue<TEvent, AUDIO_PARAM_MAX_QUEUED_EVENTS, EventComparator> eventQueue_;
5561
};
5662

5763
} // namespace audioapi

packages/react-native-audio-api/common/cpp/audioapi/utils/BoundedPriorityQueue.hpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <array>
34
#include <cstddef>
45
#include <functional>
56
#include <memory_resource>
@@ -28,9 +29,9 @@ class BoundedPriorityQueue {
2829
static constexpr size_t kBufferSize = Capacity * kNodeSize + 256;
2930

3031
// Members must be declared in this order: buffer_ → mono_ → pool_ → set_.
31-
alignas(std::max_align_t) std::byte buffer_[kBufferSize];
32+
alignas(std::max_align_t) std::array<std::byte, kBufferSize> buffer_;
3233
std::pmr::monotonic_buffer_resource mono_{
33-
buffer_,
34+
buffer_.data(),
3435
sizeof(buffer_),
3536
std::pmr::null_memory_resource()};
3637
std::pmr::unsynchronized_pool_resource pool_{
@@ -43,7 +44,7 @@ class BoundedPriorityQueue {
4344
public:
4445
/// @brief Forward iterator that exposes const T& directly.
4546
struct Iterator {
46-
typename SetType::const_iterator inner_;
47+
SetType::const_iterator inner_;
4748

4849
const T &operator*() const noexcept {
4950
return *inner_;
@@ -68,14 +69,17 @@ class BoundedPriorityQueue {
6869

6970
BoundedPriorityQueue(const BoundedPriorityQueue &) = delete;
7071
BoundedPriorityQueue &operator=(const BoundedPriorityQueue &) = delete;
72+
BoundedPriorityQueue(BoundedPriorityQueue &&) noexcept = delete;
73+
BoundedPriorityQueue &operator=(BoundedPriorityQueue &&) noexcept = delete;
7174

7275
/// @brief Insert a value in sorted order. Amortized O(1) when inserting the largest element
7376
/// (common case: events scheduled in chronological order), O(log n) otherwise.
7477
/// @return True if inserted, false if full.
7578
template <typename U>
7679
bool push(U &&value) {
77-
if (isFull()) [[unlikely]]
78-
return false;
80+
if (isFull()) {
81+
[[unlikely]] return false;
82+
}
7983
// Hint with end(): amortized O(1) when the new event has the largest key (in-order scheduling).
8084
set_.insert(set_.end(), std::forward<U>(value));
8185
return true;
@@ -84,8 +88,9 @@ class BoundedPriorityQueue {
8488
/// @brief Remove and return the smallest element (front). Amortized O(1).
8589
/// @return True if successful, false if empty.
8690
bool pop(T &out) {
87-
if (isEmpty()) [[unlikely]]
88-
return false;
91+
if (isEmpty()) {
92+
[[unlikely]] return false;
93+
}
8994
auto node = set_.extract(set_.begin());
9095
out = std::move(node.value());
9196
return true;
@@ -94,54 +99,56 @@ class BoundedPriorityQueue {
9499
/// @brief Remove the smallest element (front) without retrieving it. Amortized O(1).
95100
/// @return True if successful, false if empty.
96101
bool pop() {
97-
if (isEmpty()) [[unlikely]]
98-
return false;
102+
if (isEmpty()) {
103+
[[unlikely]] return false;
104+
}
99105
set_.erase(set_.begin());
100106
return true;
101107
}
102108

103109
/// @brief Remove the largest element (back). Amortized O(1).
104110
/// @return True if successful, false if empty.
105111
bool popBack() {
106-
if (isEmpty()) [[unlikely]]
107-
return false;
112+
if (isEmpty()) {
113+
[[unlikely]] return false;
114+
}
108115
set_.erase(std::prev(set_.end()));
109116
return true;
110117
}
111118

112119
/// @brief Peek at the smallest element (front).
113-
[[nodiscard]] inline const T &peekFront() const noexcept {
120+
[[nodiscard]] const T &peekFront() const noexcept {
114121
return *set_.begin();
115122
}
116123

117124
/// @brief Peek at the smallest element (front), mutable.
118-
[[nodiscard]] inline T &peekFrontMut() noexcept {
125+
[[nodiscard]] T &peekFrontMut() noexcept {
119126
return const_cast<T &>(*set_.begin());
120127
}
121128

122129
/// @brief Peek at the largest element (back).
123-
[[nodiscard]] inline const T &peekBack() const noexcept {
130+
[[nodiscard]] const T &peekBack() const noexcept {
124131
return *std::prev(set_.end());
125132
}
126133

127134
/// @brief Peek at the largest element (back), mutable.
128-
[[nodiscard]] inline T &peekBackMut() noexcept {
135+
[[nodiscard]] T &peekBackMut() noexcept {
129136
return const_cast<T &>(*std::prev(set_.end()));
130137
}
131138

132-
[[nodiscard]] inline bool isEmpty() const noexcept {
139+
[[nodiscard]] bool isEmpty() const noexcept {
133140
return set_.empty();
134141
}
135142

136-
[[nodiscard]] inline bool isFull() const noexcept {
143+
[[nodiscard]] bool isFull() const noexcept {
137144
return set_.size() >= Capacity;
138145
}
139146

140-
[[nodiscard]] inline size_t size() const noexcept {
147+
[[nodiscard]] size_t size() const noexcept {
141148
return set_.size();
142149
}
143150

144-
[[nodiscard]] inline size_t getCapacity() const noexcept {
151+
[[nodiscard]] size_t getCapacity() const noexcept {
145152
return Capacity;
146153
}
147154

0 commit comments

Comments
 (0)