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
base: master
Are you sure you want to change the base?
Conversation
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. |
3f840a7
to
63337c5
Compare
There was a problem hiding this 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.
Common/Serialize/SerializeMap.h
Outdated
for (auto it = x.begin(), end = x.end(); it != end; ++it) { | ||
if (it->second != nullptr) | ||
delete it->second; | ||
for (const auto &[_,value] : x) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 37ce2a4
Common/System/OSD.cpp
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tabs are wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 37ce2a4
Common/System/OSD.cpp
Outdated
} | ||
} | ||
iter->endTime = time_now_d() + delay_s + FadeoutTime(); | ||
entry.endTime = time_now_d() + delay_s + FadeoutTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 37ce2a4
Common/UI/Root.cpp
Outdated
heldKeys.insert(hk); | ||
HeldKey k = hk; | ||
heldKeys.erase(k); | ||
k.triggerTime = now + repeatInterval; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 37ce2a4
Common/UI/Screen.cpp
Outdated
for (auto iter = stack_.begin(); iter != stack_.end(); ++iter) { | ||
iter->screen->resized(); | ||
for (auto &layer : stack_) { | ||
layer.screen->resized(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 37ce2a4
… C++17 and replaced on structured binding map C++17
…structured binding map C++17
63337c5
to
487d55c
Compare
There's a conflict now. |
49124dd
to
e14cf8c
Compare
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 |
Common/Input/InputState.cpp
Outdated
@@ -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()); |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it 4ce7077
Common/Serialize/SerializeList.h
Outdated
typename std::list<T>::iterator itr, end; | ||
for (itr = x.begin(), end = x.end(); itr != end; ++itr) | ||
Do(p, *itr); | ||
for (T elem : x) |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it here 4ce7077
for (const auto &[_, value] : x) { | ||
if (value != nullptr) | ||
delete value; |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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.
Common/UI/Root.cpp
Outdated
// 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; |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert it here 4ce7077
@hrydgard, #18559 (comment) |
…heckins@unknownbrackets.org> Signed-off-by: Unknown W. Brackets <checkins@unknownbrackets.org> Co-authored-by: Unknown W. Brackets <checkins@unknownbrackets.org>
@hrydgard, and I noticed that in github I can add commit to PR on Web version, it's convenient. Done. |
You have not resolved 2 conversations with Unknown regarding your changes, apparently the one in |
@hrydgard, im fixed all conflicts and add fixes Unknown to commit. |
@hrydgard Possible improvement codegeneration by compiler, improvement readability, reduction code size.