fgerlits commented on code in PR #1354:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1354#discussion_r925685975
##########
libminifi/src/c2/C2Agent.cpp:
##########
@@ -254,7 +256,7 @@ void C2Agent::serializeMetrics(C2Payload &metric_payload,
const std::string &nam
const auto payloads = std::count_if(begin(metrics), end(metrics), [](const
state::response::SerializedResponseNode& metric) { return
!metric.children.empty() || metric.keep_empty; });
metric_payload.reservePayloads(metric_payload.getNestedPayloads().size() +
payloads);
for (const auto &metric : metrics) {
- if (metric.children.size() > 0 || (metric.children.size() == 0 &&
metric.keep_empty)) {
+ if (!metric.children.empty() || (metric.children.empty() &&
metric.keep_empty)) {
Review Comment:
minor, but I think this would read better (and would be slightly shorter) as
```suggestion
if (metric.keep_empty || !metric.children.empty()) {
```
##########
main/AgentDocs.h:
##########
@@ -26,7 +26,7 @@ class AgentDocs {
public:
void generate(const std::string &docsdir, std::ostream &genStream);
private:
- [[nodiscard]] inline std::string extractClassName(const std::string
&processor) const;
+ [[nodiscard]] static inline std::string extractClassName(const std::string
&processor);
Review Comment:
this isn't really `inline`
##########
extensions/standard-processors/tests/unit/GetFileTests.cpp:
##########
@@ -40,9 +40,9 @@ namespace {
class GetFileTestController {
public:
GetFileTestController();
- [[nodiscard]] std::string getFullPath(const std::string filename) const;
+ [[nodiscard]] std::string getFullPath(const std::string& filename) const;
[[nodiscard]] std::string getInputFilePath() const;
- void setProperty(const core::Property& property, const std::string& value);
+ void setProperty(const core::Property& property, const std::string& value)
const;
Review Comment:
Does clang-tidy want us to mark `setProperty()` `const`? It modifies the
state of the contained `test_plan_`, so I would not call it `const`. It can
only be marked `const` because `test_plan_` is a pointer.
##########
libminifi/src/core/Processor.cpp:
##########
@@ -304,18 +303,13 @@ bool Processor::isThrottledByBackpressure() const {
}
return false;
})();
Review Comment:
`isThrottledByOutgoing` could be rewritten with `ranges::any_of` (or two of
them) similar to `isForcedByIncomingCycle`
##########
extensions/http-curl/client/HTTPClient.cpp:
##########
@@ -437,29 +439,24 @@ void HTTPClient::setFollowRedirects(bool follow) {
}
bool HTTPClient::isValidHttpHeaderField(std::string_view field_name) {
- if (field_name.size() == 0) {
+ if (field_name.empty()) {
return false;
}
// RFC822 3.1.2: The field-name must be composed of printable ASCII
characters
// (i.e., characters that have values between 33. and 126., decimal,
except colon).
- for (auto ch : field_name) {
- if (ch < 33 || ch > 126 || ch == ':') {
- return false;
- }
- }
- return true;
+ return ranges::all_of(field_name, [](char c) { return c >= 33 && c <= 126 &&
c != ':'; });
}
std::string
HTTPClient::replaceInvalidCharactersInHttpHeaderFieldName(std::string_view
field_name) {
- if (field_name.size() == 0) {
+ if (field_name.empty()) {
return "X-MiNiFi-Empty-Attribute-Name";
}
std::string result;
// RFC822 3.1.2: The field-name must be composed of printable ASCII
characters
// (i.e., characters that have values between 33. and 126., decimal,
except colon).
- for (auto ch : field_name) {
+ for (auto ch : field_name) { // NOLINT(readability-use-anyofallof)
Review Comment:
Instead of the NOLINT, we could change this to a `transform` (also changing
the parameter type to `std::string`):
```c++
#include "range/v3/action/transform.hpp"
// ...
ranges::actions::transform(field_name, [](char ch) {
return (ch >= 33 && ch <= 126 && ch != ':') ? ch : '-';
});
return field_name;
```
Or if you want to keep a `string_view`, then this works:
```c++
#include "range/v3/view/transform.hpp"
#include "range/v3/range/conversion.hpp"
// ...
return ranges::views::transform(field_name, [](char ch) {
return (ch >= 33 && ch <= 126 && ch != ':') ? ch : '-';
}) | ranges::to<std::string>();
```
although it's less nice IMO.
##########
libminifi/src/core/Processor.cpp:
##########
@@ -304,18 +303,13 @@ bool Processor::isThrottledByBackpressure() const {
}
return false;
})();
- bool isForcedByIncomingCycle = ([&] {
- for (auto &inConn : incoming_connections_) {
- auto connection = dynamic_cast<Connection*>(inConn);
- if (!connection) {
- continue;
- }
- if (partOfCycle(connection) && connection->isFull()) {
- return true;
- }
+ bool isForcedByIncomingCycle = ranges::any_of(incoming_connections_,
[&](auto& inConn) {
+ auto connection = dynamic_cast<Connection*>(inConn);
+ if (!connection) {
+ return false;
}
- return false;
- })();
+ return partOfCycle(connection) && connection->isFull();
Review Comment:
this could be
```c++
return connection && partOfCycle(connection) && connection->isFull();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]