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

Migration to C++17 code refactor for loops #18559

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

Conversation

GermanAizek
Copy link
Contributor

@hrydgard Possible improvement codegeneration by compiler, improvement readability, reduction code size.

@hrydgard
Copy link
Owner

The build is failing on Windows for some reason. Take a look at the build logs and fix it up please, then I'll take a look.

Copy link
Owner

@hrydgard hrydgard left a comment

Choose a reason for hiding this comment

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

Please configure tabs in your editor correctly.

for (auto it = x.begin(), end = x.end(); it != end; ++it) {
if (it->second != nullptr)
delete it->second;
for (const auto &[_,value] : x) {
Copy link
Owner

Choose a reason for hiding this comment

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

Wow, this is getting a little to modern for me haha.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it 37ce2a4

Comment on lines 266 to 271
entry.progress = entry.maxValue;
} else {
// Fake a full progress
iter->minValue = 0;
iter->maxValue = 1;
iter->progress = 1;
entry.minValue = 0;
entry.maxValue = 1;
entry.progress = 1;
Copy link
Owner

Choose a reason for hiding this comment

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

Tabs are wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it 37ce2a4

}
}
iter->endTime = time_now_d() + delay_s + FadeoutTime();
entry.endTime = time_now_d() + delay_s + FadeoutTime();
Copy link
Owner

Choose a reason for hiding this comment

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

tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it 37ce2a4

heldKeys.insert(hk);
HeldKey k = hk;
heldKeys.erase(k);
k.triggerTime = now + repeatInterval;
Copy link
Owner

Choose a reason for hiding this comment

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

tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it 37ce2a4

for (auto iter = stack_.begin(); iter != stack_.end(); ++iter) {
iter->screen->resized();
for (auto &layer : stack_) {
layer.screen->resized();
Copy link
Owner

Choose a reason for hiding this comment

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

tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it 37ce2a4

@hrydgard
Copy link
Owner

There's a conflict now.

@hrydgard
Copy link
Owner

image

still a conflict

@GermanAizek
Copy link
Contributor Author

I don't understand how to fix it, I did same as in for-based-loop-cpp17 (range-based-loop-cpp17) branch with added emplace from master

@anr2me
Copy link
Collaborator

anr2me commented Dec 26, 2023

You need to choose one version(based on the branch name) of the change to resolve this conflict
image
either removes the code between <<<<<...===== or the code between =====...>>>>> (you can see the branch name on the right side of the arrows)

@@ -44,8 +44,8 @@ static std::unordered_map<InputDeviceID, int> uiFlipAnalogY;

static void AppendKeys(std::vector<InputMapping> &keys, const std::vector<InputMapping> &newKeys) {
keys.reserve(newKeys.size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this should actually be keys.reserve(keys.size() + newKeys.size());. If it actually even helps perf.

Any reason not to use const auto &?

-[Unknown]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it 4ce7077

typename std::list<T>::iterator itr, end;
for (itr = x.begin(), end = x.end(); itr != end; ++itr)
Do(p, *itr);
for (T elem : x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's actually important that this does not perform a copy, as it did not before.

-[Unknown]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix it here 4ce7077

Comment on lines +155 to +157
for (const auto &[_, value] : x) {
if (value != nullptr)
delete value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Personally, I like to always pretend that delete mutates a pointer, and avoid const for things I'm going to delete. Semantically, I think it'd be confusing to see a const int *p argument to a function which ends up actually deleting that pointer.

Anyway, it sometimes does in fact mutate the object by calling the destructor.

-[Unknown]

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not mistaken, delete works fine with the nullptr so the check is superfluous.

Comment on lines 366 to 371
// Cannot modify the current item when looping over a set, so let's do this instead.
HeldKey hk = *iter;
heldKeys.erase(hk);
hk.triggerTime = now + repeatInterval;
heldKeys.insert(hk);
HeldKey k = hk;
heldKeys.erase(k);
k.triggerTime = now + repeatInterval;
heldKeys.insert(k);
goto restart;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I always worry about these goto-restart things with range-fors. It's less clear what tricks the compiler might do and whether it's safe. Maybe this should be a std::remove_if pattern or something.

-[Unknown]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

revert it here 4ce7077

Core/HLE/proAdhocServer.cpp Outdated Show resolved Hide resolved
@GermanAizek
Copy link
Contributor Author

@hrydgard,
Oh, I thought this PR had been merged for a long time, how do I fix conflicts now?

#18559 (comment)
I think requirement fixed missing space is not important

…heckins@unknownbrackets.org>


Signed-off-by: Unknown W. Brackets <checkins@unknownbrackets.org>

Co-authored-by: Unknown W. Brackets <checkins@unknownbrackets.org>
@GermanAizek
Copy link
Contributor Author

GermanAizek commented Apr 1, 2024

@hrydgard, and I noticed that in github I can add commit to PR on Web version, it's convenient. Done.

@Nemoumbra
Copy link
Contributor

Nemoumbra commented Apr 1, 2024

Oh, I thought this PR had been merged for a long time

You have not resolved 2 conversations with Unknown regarding your changes, apparently the one in SerializeList.h is very important.

@GermanAizek
Copy link
Contributor Author

@hrydgard, im fixed all conflicts and add fixes Unknown to commit.

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

Successfully merging this pull request may close these issues.

None yet

5 participants