szaszm commented on code in PR #2007:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2007#discussion_r2282748470


##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -54,9 +50,16 @@
 
 using namespace std::literals::chrono_literals;
 
-namespace org::apache::nifi::minifi::processors {
+namespace {
+struct TimeDiff {
+  auto operator()() const {
+    return std::chrono::steady_clock::now() - time_;
+  }
+  const decltype(std::chrono::steady_clock::now()) time_ = 
std::chrono::steady_clock::now();
+};

Review Comment:
   I'd do it like this, but you don't need to change it if you don't like it. I 
started thinking because I found the decltype thing weird.
   ```suggestion
   const auto start_timer = [] {
     return [start_time = std::chrono::steady_clock::now()] {
       return std::chrono::steady_clock::now() - start_time;
     };
   };
   ```



##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -95,14 +97,36 @@ void ConsumeWindowsEventLog::initialize() {
   setSupportedRelationships(Relationships);
 }
 
-bool ConsumeWindowsEventLog::insertHeaderName(wel::METADATA_NAMES &header, 
const std::string &key, const std::string & value) {
-  wel::METADATA name = 
wel::WindowsEventLogMetadata::getMetadataFromString(key);
+wel::HeaderNames ConsumeWindowsEventLog::createHeaderNames(const 
std::optional<std::string>& event_header_property) const {
+  if (!event_header_property) { return {}; }
+
+  wel::HeaderNames header_names;
+
+  const auto insert_header_name = [&header_names](const std::string& key, 
const std::string& value) {
+    if (auto metadata = magic_enum::enum_cast<wel::Metadata>(key); metadata) {
+      header_names.emplace_back(*metadata, value);
+      return true;
+    }
+    return false;
+  };
 
-  if (name != wel::METADATA::UNKNOWN) {
-    header.emplace_back(std::make_pair(name, value));
-    return true;
+  auto key_value_pairs = utils::string::split(*event_header_property, ",");
+  for (const auto& key_value_pair : key_value_pairs) {
+    auto key_value = utils::string::split(key_value_pair, "=");
+    if (key_value.size() == 2) {
+      auto key = utils::string::trim(key_value.at(0));
+      auto value = utils::string::trim(key_value.at(1));

Review Comment:
   I see lots of temporary string allocations and deallocations, I think we 
should minimize those. std::string_view and working with views could be one way.



-- 
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]

Reply via email to