Skip to content

Commit

Permalink
Prevent unnecessary string copy (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMarechal25 authored Sep 4, 2024
1 parent 7b8a284 commit 44cfcbb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/cpp/lpnamer/model/ActiveLinks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ double ActiveLink::get_already_installed_capacity() const {
}

std::string ActiveLink::get_linkor() const { return _linkor; }
const std::string& ActiveLink::linkor() const { return _linkor; }

std::string ActiveLink::get_linkex() const { return _linkex; }
const std::string& ActiveLink::linkex() const { return _linkex; }

unsigned long ActiveLink::number_of_chronicles() const {
// We don't check for correctness of the number of chronicles across profiles
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/lpnamer/model/ActiveLinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class ActiveLink {
[[nodiscard]] unsigned get_idLink() const;
[[nodiscard]] LinkName get_LinkName() const;
[[nodiscard]] std::string get_linkor() const;
[[nodiscard]] const std::string& linkor() const;
[[nodiscard]] std::string get_linkex() const;
[[nodiscard]] const std::string& linkex() const;
[[nodiscard]] double get_already_installed_capacity() const;

[[nodiscard]] std::map<unsigned int, unsigned int> McYearToChronicle() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ int ReadTimeStep(const std::string& input) {
}

void updateMapColumn(const std::vector<ActiveLink>& links,
const std::string& link_origin,
const std::string& link_destination, colId id,
const std::string_view link_origin,
const std::string_view link_destination, colId id,
int time_step,
std::map<linkId, ColumnsToChange>& mapColumn) {
auto it =
std::find_if(links.begin(), links.end(),
[&link_origin, &link_destination](const ActiveLink& link) {
return link.get_linkor() == link_origin &&
link.get_linkex() == link_destination;
return link.linkor() == link_origin &&
link.linkex() == link_destination;
});

if (it != links.end()) {
Expand Down

0 comments on commit 44cfcbb

Please sign in to comment.