-
Notifications
You must be signed in to change notification settings - Fork 915
Description
This is an Easy Hack.
Potential mentors: @Ashod @Darshan-upadhyay1110
Identify places where std::move is applied to const variables. Moving from a const object does not provide a real performance benefit because it cannot steal the internal state – it falls back to a copy. Where safe and appropriate, remove the const qualifier to enable real move semantics.
Example
Before (sub-optimal, still copies):
const std::string name = "Document";
auto title = std::move(name); // still copies because `name` is constAfter (allows move):
std::string name = "Document";
auto title = std::move(name); // moves from `name`In some cases, removing const is not appropriate (for example, if the value must not change or is shared). Only update when it's clearly safe.
Good rule of thumb
-
Remove const only when
- the variable is local
- safe ownership is clear
- and it is not used after the move
-
Do not remove const when
- meaningfully immutable
- referenced later
- part of shared state
- or a const reference / const member
Short contributor note to include
Only remove const if the variable is a local, owned value not used after the move. Never change API signatures, const references, config/state objects, or shared/global values.
Metadata
Metadata
Assignees
Type
Projects
Status