Skip to content

Commit 6856b5c

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 0b7e111 + 18ea4fe commit 6856b5c

File tree

16 files changed

+1422
-378
lines changed

16 files changed

+1422
-378
lines changed

CHANGELOG.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,62 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.8.2] - 2020-08-08
11+
12+
### Changed
13+
- Avoid closures to improve compile times. (#183)
14+
- Do not iterate to drop if empty. (#182)
15+
16+
## [v0.8.1] - 2020-07-16
17+
18+
### Added
19+
- Added `erase` and `remove` to `RawTable`. (#171)
20+
- Added `try_with_capacity` to `RawTable`. (#174)
21+
- Added methods that allow re-using a `RawIter` for `RawDrain`,
22+
`RawIntoIter`, and `RawParIter`. (#175)
23+
- Added `reflect_remove` and `reflect_insert` to `RawIter`. (#175)
24+
- Added a `drain_filter` function to `HashSet`. (#179)
25+
26+
### Changed
27+
- Deprecated `RawTable::erase_no_drop` in favor of `erase` and `remove`. (#176)
28+
- `insert_no_grow` is now exposed under the `"raw"` feature. (#180)
29+
30+
## [v0.8.0] - 2020-06-18
31+
32+
### Fixed
33+
- Marked `RawTable::par_iter` as `unsafe`. (#157)
34+
35+
### Changed
36+
- Reduced the size of `HashMap`. (#159)
37+
- No longer create tables with a capacity of 1 element. (#162)
38+
- Removed `K: Eq + Hash` bounds on `retain`. (#163)
39+
- Pulled in `HashMap` changes from rust-lang/rust (#164):
40+
- `extend_one` support on nightly.
41+
- `CollectionAllocErr` renamed to `TryReserveError`.
42+
- Added `HashSet::get_or_insert_owned`.
43+
- `Default` for `HashSet` no longer requires `T: Eq + Hash` and `S: BuildHasher`.
44+
45+
## [v0.7.2] - 2020-04-27
46+
47+
### Added
48+
- Added `or_insert_with_key` to `Entry`. (#152)
49+
50+
### Fixed
51+
- Partially reverted `Clone` optimization which was unsound. (#154)
52+
53+
### Changed
54+
- Disabled use of `const-random` by default, which prevented reproducible builds. (#155)
55+
- Optimized `repeat` function. (#150)
56+
- Use `NonNull` for buckets, which improves codegen for iterators. (#148)
57+
58+
## [v0.7.1] - 2020-03-16
59+
60+
### Added
61+
- Added `HashMap::get_key_value_mut`. (#145)
62+
63+
### Changed
64+
- Optimized `Clone` implementation. (#146)
65+
1066
## [v0.7.0] - 2020-01-31
1167

1268
### Added
@@ -175,7 +231,12 @@ This release was _yanked_ due to a breaking change for users of `no-default-feat
175231

176232
- Initial release
177233

178-
[Unreleased]: https://github.com/rust-lang/hashbrown/compare/v0.7.0...HEAD
234+
[Unreleased]: https://github.com/rust-lang/hashbrown/compare/v0.8.2...HEAD
235+
[v0.8.2]: https://github.com/rust-lang/hashbrown/compare/v0.8.1...v0.8.2
236+
[v0.8.1]: https://github.com/rust-lang/hashbrown/compare/v0.8.0...v0.8.1
237+
[v0.8.0]: https://github.com/rust-lang/hashbrown/compare/v0.7.2...v0.8.0
238+
[v0.7.2]: https://github.com/rust-lang/hashbrown/compare/v0.7.1...v0.7.2
239+
[v0.7.1]: https://github.com/rust-lang/hashbrown/compare/v0.7.0...v0.7.1
179240
[v0.7.0]: https://github.com/rust-lang/hashbrown/compare/v0.6.3...v0.7.0
180241
[v0.6.3]: https://github.com/rust-lang/hashbrown/compare/v0.6.2...v0.6.3
181242
[v0.6.2]: https://github.com/rust-lang/hashbrown/compare/v0.6.1...v0.6.2

Cargo.toml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hashbrown"
3-
version = "0.7.0"
3+
version = "0.8.2"
44
authors = ["Amanieu d'Antras <amanieu@gmail.com>"]
55
description = "A Rust port of Google's SwissTable hash map"
66
license = "Apache-2.0/MIT"
@@ -32,21 +32,23 @@ autocfg = "1"
3232
lazy_static = "1.2"
3333
rand = { version = "0.7.3", features = ["small_rng"] }
3434
rayon = "1.0"
35-
rustc-hash = "1.0"
35+
rustc-hash = "=1.0"
3636
serde_test = "1.0"
3737
doc-comment = "0.3.1"
3838

3939
[features]
40-
default = [
41-
"ahash",
42-
"ahash-compile-time-rng",
43-
"inline-more",
44-
]
40+
default = ["ahash", "inline-more"]
4541

46-
ahash-compile-time-rng = [ "ahash/compile-time-rng" ]
42+
ahash-compile-time-rng = ["ahash/compile-time-rng"]
4743
nightly = []
4844
rustc-internal-api = []
49-
rustc-dep-of-std = ["nightly", "core", "compiler_builtins", "alloc", "rustc-internal-api"]
45+
rustc-dep-of-std = [
46+
"nightly",
47+
"core",
48+
"compiler_builtins",
49+
"alloc",
50+
"rustc-internal-api",
51+
]
5052
raw = []
5153

5254
# Enables usage of `#[inline]` on far more functions than by default in this

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Add this to your `Cargo.toml`:
8484

8585
```toml
8686
[dependencies]
87-
hashbrown = "0.7"
87+
hashbrown = "0.8"
8888
```
8989

9090
Then:

benches/bench.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,55 @@ bench_suite!(
206206
iter_ahash_random,
207207
iter_std_random
208208
);
209+
210+
#[bench]
211+
fn clone_small(b: &mut Bencher) {
212+
let mut m = HashMap::new();
213+
for i in 0..10 {
214+
m.insert(i, i);
215+
}
216+
217+
b.iter(|| {
218+
black_box(m.clone());
219+
})
220+
}
221+
222+
#[bench]
223+
fn clone_from_small(b: &mut Bencher) {
224+
let mut m = HashMap::new();
225+
let mut m2 = HashMap::new();
226+
for i in 0..10 {
227+
m.insert(i, i);
228+
}
229+
230+
b.iter(|| {
231+
m2.clone_from(&m);
232+
black_box(&mut m2);
233+
})
234+
}
235+
236+
#[bench]
237+
fn clone_large(b: &mut Bencher) {
238+
let mut m = HashMap::new();
239+
for i in 0..1000 {
240+
m.insert(i, i);
241+
}
242+
243+
b.iter(|| {
244+
black_box(m.clone());
245+
})
246+
}
247+
248+
#[bench]
249+
fn clone_from_large(b: &mut Bencher) {
250+
let mut m = HashMap::new();
251+
let mut m2 = HashMap::new();
252+
for i in 0..1000 {
253+
m.insert(i, i);
254+
}
255+
256+
b.iter(|| {
257+
m2.clone_from(&m);
258+
black_box(&mut m2);
259+
})
260+
}

ci/tools.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fi
3535

3636
if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
3737
if retry rustup component add clippy ; then
38-
cargo clippy --all --target=i586-unknown-linux-gnu -- -D clippy::pedantic
38+
cargo clippy --all --target=i586-unknown-linux-gnu -- -D clippy::all -D clippy::pedantic
3939
fi
4040
fi
4141

src/external_trait_impls/rayon/map.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ impl<'a, K: Sync, V: Sync, S: Sync, A: AllocRef + Clone + Sync> ParallelIterator
3030
where
3131
C: UnindexedConsumer<Self::Item>,
3232
{
33-
self.map
34-
.table
35-
.par_iter()
33+
unsafe { self.map.table.par_iter() }
3634
.map(|x| unsafe {
3735
let r = x.as_ref();
3836
(&r.0, &r.1)
@@ -77,9 +75,7 @@ impl<'a, K: Sync, V: Sync, S: Sync, A: AllocRef + Clone + Sync> ParallelIterator
7775
where
7876
C: UnindexedConsumer<Self::Item>,
7977
{
80-
self.map
81-
.table
82-
.par_iter()
78+
unsafe { self.map.table.par_iter() }
8379
.map(|x| unsafe { &x.as_ref().0 })
8480
.drive_unindexed(consumer)
8581
}
@@ -121,9 +117,7 @@ impl<'a, K: Sync, V: Sync, S: Sync, A: AllocRef + Clone + Sync> ParallelIterator
121117
where
122118
C: UnindexedConsumer<Self::Item>,
123119
{
124-
self.map
125-
.table
126-
.par_iter()
120+
unsafe { self.map.table.par_iter() }
127121
.map(|x| unsafe { &x.as_ref().1 })
128122
.drive_unindexed(consumer)
129123
}
@@ -167,9 +161,7 @@ impl<'a, K: Send + Sync, V: Send, S: Send, A: AllocRef + Clone + Sync> ParallelI
167161
where
168162
C: UnindexedConsumer<Self::Item>,
169163
{
170-
self.map
171-
.table
172-
.par_iter()
164+
unsafe { self.map.table.par_iter() }
173165
.map(|x| unsafe {
174166
let r = x.as_mut();
175167
(&r.0, &mut r.1)
@@ -207,9 +199,7 @@ impl<'a, K: Send, V: Send, S: Send, A: AllocRef + Clone + Send> ParallelIterator
207199
where
208200
C: UnindexedConsumer<Self::Item>,
209201
{
210-
self.map
211-
.table
212-
.par_iter()
202+
unsafe { self.map.table.par_iter() }
213203
.map(|x| unsafe { &mut x.as_mut().1 })
214204
.drive_unindexed(consumer)
215205
}

src/external_trait_impls/rayon/raw.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::raw::Bucket;
2-
use crate::raw::{AllocRef, RawIterRange, RawTable};
2+
use crate::raw::{AllocRef, RawIter, RawIterRange, RawTable};
33
use crate::scopeguard::guard;
44
use alloc::alloc::dealloc;
55
use core::marker::PhantomData;
@@ -15,6 +15,12 @@ pub struct RawParIter<T> {
1515
iter: RawIterRange<T>,
1616
}
1717

18+
impl<T> From<RawIter<T>> for RawParIter<T> {
19+
fn from(it: RawIter<T>) -> Self {
20+
RawParIter { iter: it.iter }
21+
}
22+
}
23+
1824
impl<T> ParallelIterator for RawParIter<T> {
1925
type Item = Bucket<T>;
2026

@@ -169,9 +175,9 @@ impl<T> Drop for ParDrainProducer<T> {
169175
impl<T, A: AllocRef + Clone> RawTable<T, A> {
170176
/// Returns a parallel iterator over the elements in a `RawTable`.
171177
#[cfg_attr(feature = "inline-more", inline)]
172-
pub fn par_iter(&self) -> RawParIter<T> {
178+
pub unsafe fn par_iter(&self) -> RawParIter<T> {
173179
RawParIter {
174-
iter: unsafe { self.iter().iter },
180+
iter: self.iter().iter,
175181
}
176182
}
177183

src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
test,
2020
core_intrinsics,
2121
dropck_eyepatch,
22+
min_specialization,
23+
extend_one,
2224
)
2325
)]
2426
#![allow(
2527
clippy::doc_markdown,
2628
clippy::module_name_repetitions,
27-
clippy::must_use_candidate
29+
clippy::must_use_candidate,
30+
clippy::option_if_let_else
2831
)]
2932
#![warn(missing_docs)]
3033
#![warn(rust_2018_idioms)]
@@ -106,14 +109,15 @@ pub mod hash_set {
106109
pub use crate::map::HashMap;
107110
pub use crate::set::HashSet;
108111

109-
/// Augments `AllocErr` with a `CapacityOverflow` variant.
112+
/// The error type for `try_reserve` methods.
110113
#[derive(Clone, PartialEq, Eq, Debug)]
111-
pub enum CollectionAllocErr {
114+
pub enum TryReserveError {
112115
/// Error due to the computed capacity exceeding the collection's maximum
113116
/// (usually `isize::MAX` bytes).
114117
CapacityOverflow,
115-
/// Error due to the allocator.
116-
AllocErr {
118+
119+
/// The memory allocator returned an error
120+
AllocError {
117121
/// The layout of the allocation request that failed.
118122
layout: alloc::alloc::Layout,
119123
},

src/macros.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,18 @@ macro_rules! cfg_if {
5252
$(#[$m] $it)*
5353
};
5454
}
55+
56+
// Helper macro for specialization. This also helps avoid parse errors if the
57+
// default fn syntax for specialization changes in the future.
58+
#[cfg(feature = "nightly")]
59+
macro_rules! default_fn {
60+
($($tt:tt)*) => {
61+
default $($tt)*
62+
}
63+
}
64+
#[cfg(not(feature = "nightly"))]
65+
macro_rules! default_fn {
66+
($($tt:tt)*) => {
67+
$($tt)*
68+
}
69+
}

0 commit comments

Comments
 (0)