Skip to content

Minor cleanup of hashmap #7875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mstewartgallus
Copy link
Contributor

No description provided.

Some(v) => v,
None => fail!("No entry found for key: %?", k),
}
self.find(k).expect(fmt!("No entry found for key: %?", k))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might actually be a substantial perf regression. Before, there was no allocation performed unless failure, but this unconditionally allocates a format string. Would you mind benchmarking to see if this is an issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will definitely be a performance issue to have allocations in any of these code paths. The only allocations it does do are the amortized resizes.

@mstewartgallus
Copy link
Contributor Author

Your right alexcrichton foo.expect(CONSTANT) makes sense but foo.expect(expr()) is silly sometimes. I'll post a benchmark soon. The stats for rustc --test --opt-level=3 std.rs && ../std --bench hashmap for both versions should work fine as a benchmark right? Or would you appreciate more info?

@huonw
Copy link
Member

huonw commented Jul 18, 2013

@sstewartgallus I don't think there are any #[bench]s on hashmap in std itself, are there?

@mstewartgallus
Copy link
Contributor Author

None of the micro-benchmarks seem to target the get methods so I'm leaving the expect changes off this pull request for now. I, or someone else can add those kind of changes later after I make a different pull request that adds some more benchmarks targeting std::hashmap.

@thestinger
Copy link
Contributor

@sstewartgallus: needs to be rebased already

@bors bors closed this Jul 23, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 4, 2021
Add unit-hash lint

changelog: [`unit_hash`] Add lint for hashing unit values

This will lint for situations where the end user is attempting to hash a unit value (`()`), as the implementation in `std` simply [does nothing][impl]. Closes rust-lang#7159 .

Example:

```rust
().hash(&mut state);

// Should (probably) be replaced with:
0_u8.hash(&mut state);
```

[impl]: https://github.com/rust-lang/rust/blob/a5f164faad4a2fed606b8160fd7ecd2d5cbba381/library/core/src/hash/mod.rs#L656
Sign up for free to 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.

6 participants