mithro / duck2-gsoc

Repository to track things that duck2 will work on for Google Summer of Code
0 stars 0 forks source link

Investigate if more `const` or reference usage in metadata rr_graph code? #21

Open mithro opened 5 years ago

mithro commented 5 years ago

https://stackoverflow.com/questions/10789740/passing-stdstring-by-value-or-reference

1) Using the string as an id (will not be modified). Passing it in by const reference is probably the best idea here: (std::string const&) ... 4) Sending the string into the function and the caller of the function will never use the string again. Using move semantics might be an option (std::string &&)

However;

This means in C++11 we can get better performance by using pass-by-value approach when:

  1. The parameter type supports move semantics - All standard library components do in C++11
    1. The cost of move constructor is much cheaper than the copy constructor (both the time and stack usage).
    2. Inside the function, the parameter type will be passed to another function or operation which supports both copy and move.
    3. It is common to pass a temporary as the argument - You can organize you code to do this more.

More info at https://codereview.stackexchange.com/questions/32842/passing-parameters-by-reference

const t_metadata_value* rr_node_metadata(int src_node, const std::string const & key);

void add_rr_node_metadata(int src_node, const  std::string key, const std::string const &  std::string value);
const t_metadata_value* rr_edge_metadata(int src_node, int sink_id, short switch_id, const const std::string const & key);

void add_rr_edge_metadata(int src_node, int sink_id, short switch_id, const std::string const & key, const std::string const & value)
mithro commented 5 years ago

Also see https://www.codesynthesis.com/~boris/blog/2012/06/19/efficient-argument-passing-cxx11-part1/

Efficient argument passing in C++11, Part 1
mithro commented 5 years ago

https://www.modernescpp.com/index.php/c-core-guidelines-how-to-pass-function-parameters

C++ Core Guidelines: The Rules for in, out, in-out, consume, and forward Function Parameter - ModernesCpp.com
mithro commented 5 years ago

https://abseil.io/tips/117

abseil / Tip of the Week #117: Copy Elision and Pass-by-value
An open-source collection of core C++ library code
mithro commented 5 years ago

https://abseil.io/tips/77

abseil / Tip of the Week #77: Temporaries, Moves, and Copies
An open-source collection of core C++ library code