Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: clang-tidy fixes around const std::string references. #1764

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mithro
Copy link
Contributor

@mithro mithro commented Jun 3, 2021

Description

This is the clang-tidy fixes that @luk036 had in his pull request at #1078

These changes make the code follow closer to best practices around using const std::string references.

@mithro mithro requested a review from hzeller June 3, 2021 21:45
@github-actions github-actions bot added ABC ABC Logic Optimization & Technology Mapping Tool external_libs libarchfpga Library for handling FPGA Architecture descriptions libvtrutil Odin Odin II Logic Synthesis Tool: Unsorted item VPR VPR FPGA Placement & Routing Tool libpugiutil labels Jun 3, 2021
@mithro
Copy link
Contributor Author

mithro commented Jun 3, 2021

This change isn't quite ready to be merged yet as it currently includes changes to code under libs/EXTERNAL. These need to be extracted out of the pull request and sent to the appropriate external projects.

@mithro mithro changed the title clang-tidy fixes around const std::string references. WIP: clang-tidy fixes around const std::string references. Jun 3, 2021
@mithro mithro mentioned this pull request Jun 3, 2021
7 tasks
void* value = NULL;
auto v = this->my_map.find(key);
if (v != this->my_map.end()) {
value = v->second;
this->my_map.erase(v);
value = this->my_map[key];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a good strategy, the original v = v->second is what we want.
Because otherwise what we do here is to look up the value again which we already did before.

Copy link
Contributor

@hzeller hzeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a first quick scan, but these are a lot of files, and there are many questionable 'improvements' in there.

So I suggest to find the clang-tidy changes that only deal with std::string -> const std::string & in parameters as first step, which makes it easier to blanket review as it not contains hidden 'gems' of other things in there.

value = v->second;
this->my_map.erase(v);
value = this->my_map[key];
this->my_map.erase(key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, this also doesn't look like the right strategy. Here again we force the map to look up the value from the key.
But we already have the iterator. So here as well, the original code is better.

void* value = NULL;
auto v = this->my_map.find(key);
if (v != this->my_map.end())
value = v->second;
value = this->my_map[key];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this should be the original v->second


return value;
}

bool Hashtable::is_empty() {
return my_map.empty();
return (my_map.size() == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This as well should be the original code my_map.empty(), not call to size().

void* value = NULL;
auto v = this->my_map.find(key);
if (v != this->my_map.end())
value = v->second;
value = this->my_map[key];

return value;
}

bool Hashtable::is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to make this is_empty() call a const method. As well Hashtable::get(). But I guess this is out of the scope for this change.

@@ -520,7 +521,7 @@ void change_to_number_node(ast_node_t* node, VNumber number) {

node->type = NUMBERS;
node->types.identifier = temp_ident;
node->types.vnumber = new VNumber(number);
node->types.vnumber = new VNumber(std::move(number));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably keep changes that involve std::move in a separate change to keep it by const std::string &.

(I'd only use std::move if really needed. It more uglifies code otherwise)

@@ -45,7 +45,7 @@ struct Abc_ManTime_t_

#define TOLERANCE 0.001

static inline int Abc_FloatEqual( float x, float y ) { return fabs(x-y) < TOLERANCE; }
static inline int Abc_FloatEqual( float x, float y ) { return fabsf(x-y) < TOLERANCE; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The abc/ directory is probably also something that is just imported and we shouldn't touch too much.

@@ -84,7 +85,7 @@ PowerCallibSize* PowerCallibInputs::get_entry_bound(bool lower,

PowerSpicedComponent::PowerSpicedComponent(std::string component_name,
float (*usage_fn)(int num_inputs, float transistor_size)) {
name = component_name;
name = std::move(component_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of calling std::move here, we should pass a const std::string & as parameter, and just use assignment here.

@@ -131,19 +132,19 @@ int RoutingToClockConnection::create_virtual_clock_network_sink_node(
*/

void ClockToClockConneciton::set_from_clock_name(std::string clock_name) {
from_clock = clock_name;
from_clock = std::move(clock_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these: instead of using std::move from a by-value parameter, we should use assignment and pass in a const std::string &

@vaughnbetz
Copy link
Contributor

@luk036 : feedback from @hzeller on these clang-tidy changes. Looks like we'd only want a subset of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABC ABC Logic Optimization & Technology Mapping Tool external_libs libarchfpga Library for handling FPGA Architecture descriptions libpugiutil libvtrutil Odin Odin II Logic Synthesis Tool: Unsorted item VPR VPR FPGA Placement & Routing Tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants