-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
A-lintArea: New lintsArea: New lints
Description
What it does
Like manual_memcpy, find for-loops equivalent to slice::copy_within.
Lint Name
manual_memmove
Category
perf
Advantage
It's shorter and faster.
Drawbacks
any case where memmove is not actually faster? (should probably file as bug against rust though)
Example
let mut arr: [u8; 4] = [1, 2, 3, 4];
for i in 0..2 {
arr[i] = arr[i + 2];
}Could be written as:
arr.copy_within(2..4, 0);Implementation notes
More generally:
for i in a..b {
arr[i] = arr[i + offset];
}Could be written as:
arr.copy_within((a + offset)..(b + offset), a);Definetly need to look at implementation of manual_memmove and its tests to cover all the edgecases around false-positives here.
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints