[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-30 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/nifi-minifi-cpp/pull/346


---


[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-29 Thread phrocker
Github user phrocker commented on a diff in the pull request:

https://github.com/apache/nifi-minifi-cpp/pull/346#discussion_r191489985
  
--- Diff: libminifi/src/controllers/NetworkPrioritizerService.cpp ---
@@ -65,33 +65,38 @@ void NetworkPrioritizerService::yield() {
 /**
  * If not an intersecting operation we will attempt to locate the highest 
priority interface available.
  */
-io::NetworkInterface &::getInterface(uint32_t 
size = 0) {
+io::NetworkInterface NetworkPrioritizerService::getInterface(uint32_t size 
= 0) {
   std::vector controllers;
+  std::string ifc = "";
   if (!network_controllers_.empty()) {
 if (sufficient_tokens(size) && size < max_payload_) {
   controllers.insert(std::end(controllers), 
std::begin(network_controllers_), std::end(network_controllers_));
 }
   }
 
   if (!controllers.empty()) {
-auto ifc = get_nearest_interface(controllers);
+ifc = get_nearest_interface(controllers);
 if (!ifc.empty()) {
   reduce_tokens(size);
-  return std::move(io::NetworkInterface(ifc, shared_from_this()));
+  io::NetworkInterface newifc(ifc, shared_from_this());
+  return newifc;
 }
   }
   for (size_t i = 0; i < linked_services_.size(); i++) {
 auto np = 
std::dynamic_pointer_cast(linked_services_.at(i));
 if (np != nullptr) {
   auto ifcs = np->getInterfaces(size);
-  auto ifc = get_nearest_interface(ifcs);
+  ifc = get_nearest_interface(ifcs);
   if (!ifc.empty()) {
 np->reduce_tokens(size);
-return std::move(io::NetworkInterface(ifc, np));
+io::NetworkInterface newifc(ifc, np);
+return newifc;
--- End diff --

same explanation as above. net result in the assembly is different in only 
that RVO isn't occurring with ifc. 


---


[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-29 Thread phrocker
Github user phrocker commented on a diff in the pull request:

https://github.com/apache/nifi-minifi-cpp/pull/346#discussion_r191487153
  
--- Diff: libminifi/src/controllers/NetworkPrioritizerService.cpp ---
@@ -65,33 +65,38 @@ void NetworkPrioritizerService::yield() {
 /**
  * If not an intersecting operation we will attempt to locate the highest 
priority interface available.
  */
-io::NetworkInterface &::getInterface(uint32_t 
size = 0) {
+io::NetworkInterface NetworkPrioritizerService::getInterface(uint32_t size 
= 0) {
   std::vector controllers;
+  std::string ifc = "";
   if (!network_controllers_.empty()) {
 if (sufficient_tokens(size) && size < max_payload_) {
   controllers.insert(std::end(controllers), 
std::begin(network_controllers_), std::end(network_controllers_));
 }
   }
 
   if (!controllers.empty()) {
-auto ifc = get_nearest_interface(controllers);
+ifc = get_nearest_interface(controllers);
 if (!ifc.empty()) {
   reduce_tokens(size);
-  return std::move(io::NetworkInterface(ifc, shared_from_this()));
+  io::NetworkInterface newifc(ifc, shared_from_this());
+  return newifc;
--- End diff --

That caused issue on one distro I tested in regards to the transient 
string. the string was being elided causing an access an error later. In this 
case the optimization didn't happen. It seems to be specific to that U18 
compiler, so I took this route and this avoided the problem with valgrind 
verification. 


---


[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-29 Thread achristianson
Github user achristianson commented on a diff in the pull request:

https://github.com/apache/nifi-minifi-cpp/pull/346#discussion_r191486780
  
--- Diff: libminifi/src/controllers/NetworkPrioritizerService.cpp ---
@@ -65,33 +65,38 @@ void NetworkPrioritizerService::yield() {
 /**
  * If not an intersecting operation we will attempt to locate the highest 
priority interface available.
  */
-io::NetworkInterface &::getInterface(uint32_t 
size = 0) {
+io::NetworkInterface NetworkPrioritizerService::getInterface(uint32_t size 
= 0) {
   std::vector controllers;
+  std::string ifc = "";
   if (!network_controllers_.empty()) {
 if (sufficient_tokens(size) && size < max_payload_) {
   controllers.insert(std::end(controllers), 
std::begin(network_controllers_), std::end(network_controllers_));
 }
   }
 
   if (!controllers.empty()) {
-auto ifc = get_nearest_interface(controllers);
+ifc = get_nearest_interface(controllers);
 if (!ifc.empty()) {
   reduce_tokens(size);
-  return std::move(io::NetworkInterface(ifc, shared_from_this()));
+  io::NetworkInterface newifc(ifc, shared_from_this());
+  return newifc;
 }
   }
   for (size_t i = 0; i < linked_services_.size(); i++) {
 auto np = 
std::dynamic_pointer_cast(linked_services_.at(i));
 if (np != nullptr) {
   auto ifcs = np->getInterfaces(size);
-  auto ifc = get_nearest_interface(ifcs);
+  ifc = get_nearest_interface(ifcs);
   if (!ifc.empty()) {
 np->reduce_tokens(size);
-return std::move(io::NetworkInterface(ifc, np));
+io::NetworkInterface newifc(ifc, np);
+return newifc;
   }
 }
   }
-  return std::move(io::NetworkInterface("", nullptr));
+
+  io::NetworkInterface newifc(ifc, nullptr);
+  return newifc;
--- End diff --

Ditto (trival though).


---


[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-29 Thread achristianson
Github user achristianson commented on a diff in the pull request:

https://github.com/apache/nifi-minifi-cpp/pull/346#discussion_r191486723
  
--- Diff: libminifi/src/controllers/NetworkPrioritizerService.cpp ---
@@ -65,33 +65,38 @@ void NetworkPrioritizerService::yield() {
 /**
  * If not an intersecting operation we will attempt to locate the highest 
priority interface available.
  */
-io::NetworkInterface &::getInterface(uint32_t 
size = 0) {
+io::NetworkInterface NetworkPrioritizerService::getInterface(uint32_t size 
= 0) {
   std::vector controllers;
+  std::string ifc = "";
   if (!network_controllers_.empty()) {
 if (sufficient_tokens(size) && size < max_payload_) {
   controllers.insert(std::end(controllers), 
std::begin(network_controllers_), std::end(network_controllers_));
 }
   }
 
   if (!controllers.empty()) {
-auto ifc = get_nearest_interface(controllers);
+ifc = get_nearest_interface(controllers);
 if (!ifc.empty()) {
   reduce_tokens(size);
-  return std::move(io::NetworkInterface(ifc, shared_from_this()));
+  io::NetworkInterface newifc(ifc, shared_from_this());
+  return newifc;
 }
   }
   for (size_t i = 0; i < linked_services_.size(); i++) {
 auto np = 
std::dynamic_pointer_cast(linked_services_.at(i));
 if (np != nullptr) {
   auto ifcs = np->getInterfaces(size);
-  auto ifc = get_nearest_interface(ifcs);
+  ifc = get_nearest_interface(ifcs);
   if (!ifc.empty()) {
 np->reduce_tokens(size);
-return std::move(io::NetworkInterface(ifc, np));
+io::NetworkInterface newifc(ifc, np);
+return newifc;
--- End diff --

Likewise.


---


[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-29 Thread phrocker
Github user phrocker commented on a diff in the pull request:

https://github.com/apache/nifi-minifi-cpp/pull/346#discussion_r191486678
  
--- Diff: libminifi/include/io/NetworkPrioritizer.h ---
@@ -86,10 +92,15 @@ class NetworkInterface {
   friend class NetworkPrioritizer;
   std::string ifc_;
   std::shared_ptr prioritizer_;
-};
+}
+;
--- End diff --

We can't really do that since we have a custom google style format, but 
thanks for pointing that out. 


---


[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-29 Thread achristianson
Github user achristianson commented on a diff in the pull request:

https://github.com/apache/nifi-minifi-cpp/pull/346#discussion_r191486681
  
--- Diff: libminifi/src/controllers/NetworkPrioritizerService.cpp ---
@@ -65,33 +65,38 @@ void NetworkPrioritizerService::yield() {
 /**
  * If not an intersecting operation we will attempt to locate the highest 
priority interface available.
  */
-io::NetworkInterface &::getInterface(uint32_t 
size = 0) {
+io::NetworkInterface NetworkPrioritizerService::getInterface(uint32_t size 
= 0) {
   std::vector controllers;
+  std::string ifc = "";
   if (!network_controllers_.empty()) {
 if (sufficient_tokens(size) && size < max_payload_) {
   controllers.insert(std::end(controllers), 
std::begin(network_controllers_), std::end(network_controllers_));
 }
   }
 
   if (!controllers.empty()) {
-auto ifc = get_nearest_interface(controllers);
+ifc = get_nearest_interface(controllers);
 if (!ifc.empty()) {
   reduce_tokens(size);
-  return std::move(io::NetworkInterface(ifc, shared_from_this()));
+  io::NetworkInterface newifc(ifc, shared_from_this());
+  return newifc;
--- End diff --

Why not just return io::NetworkInterface(ifc, shared_from_this())?


---


[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-29 Thread achristianson
Github user achristianson commented on a diff in the pull request:

https://github.com/apache/nifi-minifi-cpp/pull/346#discussion_r191486381
  
--- Diff: libminifi/include/io/NetworkPrioritizer.h ---
@@ -86,10 +92,15 @@ class NetworkInterface {
   friend class NetworkPrioritizer;
   std::string ifc_;
   std::shared_ptr prioritizer_;
-};
+}
+;
--- End diff --

Minor style nit. May want to run through clang-format --style=Google.


---


[GitHub] nifi-minifi-cpp pull request #346: MINIFICPP-513: Avoid rvalue ref and move ...

2018-05-28 Thread phrocker
GitHub user phrocker opened a pull request:

https://github.com/apache/nifi-minifi-cpp/pull/346

MINIFICPP-513: Avoid rvalue ref and move semantics. let compiler take…

… care of movement optimization

Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced
 in the commit message?

- [ ] Does your PR title start with MINIFI- where  is the JIRA 
number you are trying to resolve? Pay particular attention to the hyphen "-" 
character.

- [ ] Has your PR been rebased against the latest commit within the target 
branch (typically master)?

- [ ] Is your initial contribution a single, squashed commit?

### For code changes:
- [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the LICENSE file?
- [ ] If applicable, have you updated the NOTICE file?

### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in 
which it is rendered?

### Note:
Please ensure that once the PR is submitted, you check travis-ci for build 
issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/phrocker/nifi-minifi-cpp MINIFICPP-513

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/nifi-minifi-cpp/pull/346.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #346


commit e4e826dec56902bd7dabbb084e48a0bd35684a8c
Author: Marc Parisi 
Date:   2018-05-28T14:17:50Z

MINIFICPP-513: Avoid rvalue ref and move semantics. let compiler take care 
of movement optimization




---