summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2018-03-14 02:46:28 +0300
committerEd Tanous <ed.tanous@intel.com>2018-04-20 21:25:15 +0300
commitcbbfa9672aed51df7bd2f2d7e08e9f0eb0fdb7ec (patch)
tree4bf4d26bf42f0ee681e57aa3796aabd25d91c393
parent9dc2c4d61fa1ecd3835abc83776e6e0ee2f79711 (diff)
downloadbmcweb-cbbfa9672aed51df7bd2f2d7e08e9f0eb0fdb7ec.tar.xz
Make getUrl not copy
Make get url return a const std::string* instead of a copy. Also, make the getSubroutes function modify strings in place rather than construct new strings where possible Change-Id: I68d8053a62abd8d907ecb6717e0f266eee4d09a8 Signed-off-by: Ed Tanous <ed.tanous@intel.com>
-rw-r--r--redfish-core/include/node.hpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/redfish-core/include/node.hpp b/redfish-core/include/node.hpp
index a33c8e01e5..0a1564a24a 100644
--- a/redfish-core/include/node.hpp
+++ b/redfish-core/include/node.hpp
@@ -41,12 +41,13 @@ class Node {
virtual ~Node() = default;
- std::string getUrl() const {
+ const std::string* getUrl() const {
auto odataId = json.find("@odata.id");
- if (odataId != json.end() && odataId->is_string()) {
- return odataId->get<std::string>();
+ if (odataId == json.end()) {
+ return nullptr;
}
- return std::string();
+
+ return odataId->get_ptr<const std::string*>();
}
/**
@@ -58,27 +59,35 @@ class Node {
* @return None
*/
void getSubRoutes(const std::vector<std::unique_ptr<Node>>& allNodes) {
- std::string url = getUrl();
+ const std::string* url = getUrl();
+ if (url == nullptr) {
+ CROW_LOG_CRITICAL << "Unable to get url for route";
+ return;
+ }
for (const auto& node : allNodes) {
- auto route = node->getUrl();
-
- if (boost::starts_with(route, url)) {
- auto subRoute = route.substr(url.size());
+ const std::string* route = node->getUrl();
+ if (route == nullptr) {
+ CROW_LOG_CRITICAL << "Unable to get url for route";
+ return;
+ }
+ if (boost::starts_with(*route, *url)) {
+ std::string subRoute = route->substr(url->size());
if (subRoute.empty()) {
continue;
}
- if (subRoute.at(0) == '/') {
- subRoute = subRoute.substr(1);
+ if (boost::starts_with(subRoute, "/")) {
+ subRoute.erase(0, 1);
}
- if (subRoute.at(subRoute.size() - 1) == '/') {
- subRoute = subRoute.substr(0, subRoute.size() - 1);
+ if (boost::ends_with(subRoute, "/")) {
+ subRoute.pop_back();
}
- if (subRoute[0] != '$' && subRoute.find('/') == std::string::npos) {
- json[subRoute] = nlohmann::json{{"@odata.id", route}};
+ if (!boost::starts_with(subRoute, "$") &&
+ subRoute.find('/') == std::string::npos) {
+ json[subRoute] = nlohmann::json{{"@odata.id", *route}};
}
}
}