Skip to content

Detect creation of new collection when it could be emptied #16520

@samueltardieu

Description

@samueltardieu

Description

See uutils/coreutils#10695

When a variable holding a collection (such as Vec/VecDeque/HashMap/BTreeMap) is replaced by a new empty instance, it can be more efficient to instead clear the existing one to be able to reuse the allocated memory.

For example, x = Vec::new() can be replaced by x.clear(): x will be an empty vector, except that the storage (and capacity) will be inherited from the previous instance.

Version


Additional Labels

No response

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions