-
Notifications
You must be signed in to change notification settings - Fork 119
Use move for std::vector instead of copying in path functions #1895
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
6684d6e
17353e6
0d9caa1
315d16f
e951e6c
2a5e8f8
fae8029
69c373c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -536,18 +536,30 @@ class AICommandInterface | |
| aiDoCommand(&parms); | ||
| } | ||
|
|
||
| inline void aiFollowExitProductionPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource ) | ||
| inline void aiFollowExitProductionPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource ) | ||
| { | ||
| AICommandParms parms(AICMD_FOLLOW_EXITPRODUCTION_PATH, cmdSource); | ||
| parms.m_coords = *path; | ||
| #if __cplusplus >= 201103L | ||
| parms.m_coords = std::move(*path); | ||
| #else | ||
| // TheSuperHackers @performance bobtista 23/11/2025 Use swap to emulate move semantics for VC6 compatibility | ||
| parms.m_coords.swap(*path); | ||
| path->clear(); | ||
| #endif | ||
| parms.m_obj = ignoreObject; | ||
| aiDoCommand(&parms); | ||
| } | ||
|
|
||
| inline void aiFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource ) | ||
| inline void aiFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource ) | ||
| { | ||
| AICommandParms parms(AICMD_FOLLOW_PATH, cmdSource); | ||
| parms.m_coords = *path; | ||
| #if __cplusplus >= 201103L | ||
| parms.m_coords = std::move(*path); | ||
| #else | ||
| // TheSuperHackers @performance bobtista 23/11/2025 Use swap to emulate move semantics for VC6 compatibility | ||
| parms.m_coords.swap(*path); | ||
| path->clear(); | ||
|
||
| #endif | ||
| parms.m_obj = ignoreObject; | ||
| aiDoCommand(&parms); | ||
| } | ||
|
|
||
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.
Keep it simple and use swap even for c++11
Uh oh!
There was an error while loading. Please reload this page.
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.
Swap is unnecessary here and does not convey the intended operation: a single move operation; we don't care about the contents (if anything) of
parms.m_coords.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.
Yes but then we do not need all this
#if __cplusplus >= 201103Lstuff here.Otherwise, create a "move" helper somewhere else that we use here, which does move in c++11 and swap in C++98.
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.
Ok I added a helper to CppMacros.h
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.
Ok that works. I think CppMacros.h needs renaming to to cpp_compat.h later :-)