Skip to content

Commit 4048734

Browse files
Apply suggestions from code review
Co-authored-by: kirkrodrigues <[email protected]>
1 parent 081405f commit 4048734

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

components/core/src/clp/ffi/KeyValuePairLogEvent.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ auto validate_node_id_value_pairs(
219219
for (auto const& [node_id, value] : node_id_value_pairs) {
220220
auto const& node{schema_tree.get_node(node_id)};
221221
if (node.is_root()) {
222-
// This node is the root
223222
return std::errc::operation_not_permitted;
224223
}
225224

@@ -241,7 +240,7 @@ auto validate_node_id_value_pairs(
241240
return std::errc::operation_not_permitted;
242241
}
243242

244-
// Since we checked that the node must not be the root, we can query the underlying ID
243+
// We checked that the node isn't the root above, so we can query the underlying ID
245244
// safely without a repeated check.
246245
auto const parent_node_id{node.get_parent_id_unsafe()};
247246
auto const key_name{node.get_key_name()};
@@ -298,10 +297,10 @@ auto get_schema_subtree_bitmap(
298297
// Iteratively mark the parents as true
299298
auto optional_parent_id{schema_tree.get_node(node_id).get_parent_id()};
300299
while (true) {
300+
// Ideally, we'd use this if statement as the loop condition, but clang-tidy will
301+
// complain about an unchecked `optional` access.
301302
if (false == optional_parent_id.has_value()) {
302-
// Root has been reached.
303-
// Ideally this if statement can be used as the loop condition. However, clang-tidy
304-
// will complain about unchecked optional access.
303+
// Reached the root
305304
break;
306305
}
307306
auto const parent_id{optional_parent_id.value()};

components/core/src/clp/ffi/SchemaTree.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,15 @@ class SchemaTree {
133133
[[nodiscard]] auto is_root() const -> bool { return false == m_parent_id.has_value(); }
134134

135135
/**
136-
* @return the ID of the parent node in the schema tree if the node is not root.
137-
* @return std::nullopt if the node is root.
136+
* @return The ID of the parent node in the schema tree, if the node is not the root.
137+
* @return std::nullopt if the node is the root.
138138
*/
139139
[[nodiscard]] auto get_parent_id() const -> std::optional<id_t> { return m_parent_id; }
140140

141141
/**
142-
* Gets the parent ID without checking if it is std::nullopt.
142+
* Gets the parent ID without checking if it's `std::nullopt`.
143143
* NOTE: This method should only be used if the caller has checked the node is not the root.
144-
* `is_root()` must return false to call this method safely.
145-
* @return the ID of the parent node in the schema tree.
144+
* @return The ID of the parent node in the schema tree.
146145
*/
147146
[[nodiscard]] auto get_parent_id_unsafe() const -> id_t {
148147
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
@@ -189,10 +188,9 @@ class SchemaTree {
189188

190189
/**
191190
* Creates a root node.
192-
* @param id The ID of the root node assigned by the schema tree.
193191
*/
194192
[[nodiscard]] static auto create_root() -> Node {
195-
return {cRootId, std::nullopt, "", Type::Obj};
193+
return {cRootId, std::nullopt, {}, Type::Obj};
196194
}
197195

198196
// Constructors

components/core/tests/test-ffi_SchemaTree.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ namespace {
2525
* @param schema_tree
2626
* @param locator
2727
* @param expected_id
28-
* @return Whether the node exists with its ID matches the expected ID and its information matches
29-
* the ones specified in the locator.
28+
* @return Whether an ID could be found for a node matching the locator, the ID matches the expected
29+
* ID, the corresponding node is not the root, and it matches the locator.
3030
*/
3131
[[nodiscard]] auto check_node(
3232
SchemaTree const& schema_tree,
@@ -50,17 +50,17 @@ auto check_node(
5050
) -> bool {
5151
auto const node_id{schema_tree.try_get_node_id(locator)};
5252
if (false == node_id.has_value() || node_id.value() != expected_id) {
53-
// Check node ID
53+
// The node's ID doesn't match.
5454
return false;
5555
}
5656
auto const& node{schema_tree.get_node(expected_id)};
5757
if (node.is_root()) {
58-
// The node after initialization must not be the root.
58+
// Any nodes added after the tree was constructed must not be the root.
5959
return false;
6060
}
6161
auto const optional_parent_id{node.get_parent_id()};
6262
if (false == optional_parent_id.has_value()) {
63-
// Non-root node must have a parent ID.
63+
// Non-root nodes must have a parent ID.
6464
return false;
6565
}
6666
if (optional_parent_id.value() != locator.get_parent_id()

0 commit comments

Comments
 (0)