]> git.lizzy.rs Git - rust.git/blob - src/docs/linkedlist.txt
Add iter_kv_map lint
[rust.git] / src / docs / linkedlist.txt
1 ### What it does
2 Checks for usage of any `LinkedList`, suggesting to use a
3 `Vec` or a `VecDeque` (formerly called `RingBuf`).
4
5 ### Why is this bad?
6 Gankro says:
7
8 > The TL;DR of `LinkedList` is that it's built on a massive amount of
9 pointers and indirection.
10 > It wastes memory, it has terrible cache locality, and is all-around slow.
11 `RingBuf`, while
12 > "only" amortized for push/pop, should be faster in the general case for
13 almost every possible
14 > workload, and isn't even amortized at all if you can predict the capacity
15 you need.
16 >
17 > `LinkedList`s are only really good if you're doing a lot of merging or
18 splitting of lists.
19 > This is because they can just mangle some pointers instead of actually
20 copying the data. Even
21 > if you're doing a lot of insertion in the middle of the list, `RingBuf`
22 can still be better
23 > because of how expensive it is to seek to the middle of a `LinkedList`.
24
25 ### Known problems
26 False positives – the instances where using a
27 `LinkedList` makes sense are few and far between, but they can still happen.
28
29 ### Example
30 ```
31 let x: LinkedList<usize> = LinkedList::new();
32 ```