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

Use range loop (if possible) #7770

Merged
merged 1 commit into from Jul 18, 2020
Merged

Use range loop (if possible) #7770

merged 1 commit into from Jul 18, 2020

Conversation

ghost
Copy link

@ghost ghost commented Feb 1, 2019

Should behave as original code, but without magic numbers and looks a bit simpler.

// not sure if formatting will satisfy you :(

@JosJuice
Copy link
Member

JosJuice commented Feb 1, 2019

  • Please don't touch the code in the Externals directory.
  • There should be no space before &. (I'll run the lint bot for this PR so it can point out the incorrect formatting)
  • Don't use the m_ prefix for local variables.

@ghost
Copy link
Author

ghost commented Feb 1, 2019

Should be ok now.
// one more force push, used more auto

for (size_t i = 0; i < ArraySize(g_dsp.reg_stack); i++)
std::fill(std::begin(g_dsp.reg_stack[i]), std::end(g_dsp.reg_stack[i]), 0);
for (auto& i : g_dsp.reg_stack)
std::fill(std::begin(i), std::end(i), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I dunno about using i for a loop value. Granted, in this case I'm not sure what a better name would be, but that just gives the wrong impression when glancing over the code.

You do this in a few other spots too.

Copy link
Member

Choose a reason for hiding this comment

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

That'd be the only shortcomings I see with this PR - most of those single-letter iteration variables could use a better name. Or least don't call them i which is the most likely one to be used in a plain for loop as counter.

for (size_t i = 0; i < ArraySize(key_map); i++)
ImGui::GetIO().KeyMap[key_map[i][0]] = (key_map[i][1] & 0x1FF);
for (auto i : key_map)
ImGui::GetIO().KeyMap[i[0]] = (i[1] & 0x1FF);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this use auto& too?

Copy link
Author

Choose a reason for hiding this comment

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

I think it's not needed. (if you expand up, you will see that key_map is array of ints)

@ghost
Copy link
Author

ghost commented Feb 2, 2019

Renamed a bit.

@Tilka
Copy link
Member

Tilka commented Feb 11, 2019

From the style guide:

Do not use the auto keyword everywhere. While it's nice that the type can be determined by the compiler, it cannot be resolved at 'readtime' by the developer as easily. Use auto only in cases where it is obvious what the type being assigned is (note: 'obvious' means not having to open other files or reading the header file). Some situations where it is appropriate to use auto is when iterating over a std::map container in a foreach loop, or to shorten the length of container iterator variable declarations.

Source/Core/InputCommon/GCAdapter.cpp Outdated Show resolved Hide resolved
Source/Core/InputCommon/GCAdapter.cpp Outdated Show resolved Hide resolved
Source/Core/DolphinQt/RenderWidget.cpp Outdated Show resolved Hide resolved
@ghost
Copy link
Author

ghost commented Feb 11, 2019

Small up.

@ghost
Copy link
Author

ghost commented Jul 2, 2019

Rebased.

@ghost
Copy link
Author

ghost commented Jul 2, 2019

Fixed linter error.

@jordan-woyak
Copy link
Member

Can we get another rebase, please?

@ghost
Copy link
Author

ghost commented Jul 18, 2020

@jordan-woyak, should be ok now.

@jordan-woyak jordan-woyak merged commit 5c2b6d0 into dolphin-emu:master Jul 18, 2020
10 checks passed
@ghost
Copy link
Author

ghost commented Jul 18, 2020

Thx for help with formatting.

@ghost ghost deleted the loop branch July 18, 2020 23:55
@jordan-woyak
Copy link
Member

No problem. I configure my editor to clang-format on save so I can't forget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants