Skip to content

libcore: Implement an Equiv trait and use it on hashmaps. - #5234

Closed
pcwalton wants to merge 3 commits into
rust-lang:incomingfrom
pcwalton:equiv
Closed

libcore: Implement an Equiv trait and use it on hashmaps.#5234
pcwalton wants to merge 3 commits into
rust-lang:incomingfrom
pcwalton:equiv

Conversation

@pcwalton

Copy link
Copy Markdown
Contributor

Means that we'll need another snapshot to rid the language of `[const T]`.
7.3x speedup in string map search speed on a microbenchmark of pure hashmap
searching against a constant string, due to the lack of allocations.
I ran into a few snags.
1. The way the coherence check is set up, I can't implement `Equiv<@str>` and
`Equiv<~str>` for `&str` simultaneously.
2. I wanted to implement `Equiv<T>` for all `T:Eq` (i.e. every type can be
compared to itself if it implements `Eq`), but the coherence check didn't
like that either.
3. I couldn't add this to the `Map` trait because `LinearMap` needs special
handling for its `Q` type parameter: it must not only implement `Equiv<T>`
but also `Hash` and `Eq`.
4. `find_equiv(&&"foo")` doesn't parse, because of the double ampersand. It has
to be written `find_equiv(& &"foo")`. We can probably just fix this.
Nevertheless, this is a huge win; it should address a major source of
performance problems, including the one here:
http://maniagnosis.crsr.net/2013/02/creating-letterpress-cheating-program.html
@borsbors closed this Mar 5, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 8, 2021
…, r=phansch
New Lint: `branches_sharing_code`
This lint checks if all `if`-blocks contain some statements that are the same and can be moved out of the blocks to prevent code duplication. Here is an example:
```rust
let _ = if ... {
println!("Start"); // <-- Lint for code duplication
let _a = 99;
println!("End"); // <-- Lint for code duplication
false
} else {
println!("Start");
let _b = 17;
println!("End");
false
};
```
This could be written as:
```rust
println!("Start");
let _ = if ... {
let _a = 99;
false
} else {
let _b = 17;
false
};
println!("End");
```
---
This lint will get masked by the `IF_SAME_THEN_ELSE` lint. I think it makes more sense to only emit one lint per if block. This means that the folloing example:
```rust
if ... {
let _a = 17;
} else {
let _a = 17;
}
```
Will only trigger the `IF_SAME_THEN_ELSE` lint and not the `SHARED_CODE_IN_IF_BLOCKS` lint.
---
closes: rust-lang#5234
changelog: Added a new lint: `branches_sharing_code`
And hello to the one that is writing the changelog for this release :D
calebcartwright pushed a commit to calebcartwright/rust that referenced this pull request Jun 20, 2023
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
5234: Fix: allow for binaries from $PATH to pass validity check r=matklad a=Veetaha
Tackles rust-lang/rust-analyzer#5229 (comment)
cc @matklad@lnicola Apparently `fs.existsSync()` works only with real paths and not with `$PATH` env var
Co-authored-by: Veetaha <veetaha2@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@pcwalton@bors