diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2024-02-05 09:58:08 +0100 |
---|---|---|
committer | Jeff Vander Stoep <jeffv@google.com> | 2024-02-05 09:58:08 +0100 |
commit | f4a1151ee3613c367a52e8c4ba02ce90c2cd0678 (patch) | |
tree | c1ff49d9f891c42704a17d7486b034dbed218e1a | |
parent | 4347594c5e6d984d16f0c9f9b8e0f20ce638a316 (diff) | |
download | slab-f4a1151ee3613c367a52e8c4ba02ce90c2cd0678.tar.gz |
Upgrade slab to 0.4.9
This project was upgraded with external_updater.
Usage: tools/external_updater/updater.sh update external/rust/crates/slab
For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
Test: TreeHugger
Change-Id: I66cfc750d7a3980e109009ccb8aab637f80eda5a
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 25 | ||||
-rw-r--r-- | src/lib.rs | 20 | ||||
-rw-r--r-- | tests/slab.rs | 21 |
8 files changed, 61 insertions, 21 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 4866a89..e81232e 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "151a9cea914bb8017470caeb467a208fd1ad99b3" + "sha1": "b709dcf8f0884f2e041aa6a6cb4cf54200aa5491" }, "path_in_vcs": "" }
\ No newline at end of file @@ -23,7 +23,7 @@ rust_library { host_supported: true, crate_name: "slab", cargo_env_compat: true, - cargo_pkg_version: "0.4.8", + cargo_pkg_version: "0.4.9", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -46,7 +46,7 @@ rust_test { host_supported: true, crate_name: "slab", cargo_env_compat: true, - cargo_pkg_version: "0.4.8", + cargo_pkg_version: "0.4.9", srcs: ["tests/slab.rs"], test_suites: ["general-tests"], auto_gen_config: true, diff --git a/CHANGELOG.md b/CHANGELOG.md index db54582..f46a797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -# 0.4.8 (January 20, 2022) +# 0.4.9 (August 22, 2023) + +* Avoid reallocations in `Slab::clone_from` (#137) + +# 0.4.8 (January 20, 2023) * Fixed documentation about overflow (#124) * Document panic in `get2_mut` (#131) @@ -13,7 +13,7 @@ edition = "2018" rust-version = "1.31" name = "slab" -version = "0.4.8" +version = "0.4.9" authors = ["Carl Lerche <me@carllerche.com>"] exclude = ["/.*"] description = "Pre-allocated storage for a uniform data type" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index ae94bb4..1891355 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -6,7 +6,7 @@ name = "slab" # - README.md # - Update CHANGELOG.md # - Create git tag -version = "0.4.8" +version = "0.4.9" authors = ["Carl Lerche <me@carllerche.com>"] edition = "2018" rust-version = "1.31" @@ -1,23 +1,20 @@ # This project was upgraded with external_updater. -# Usage: tools/external_updater/updater.sh update rust/crates/slab -# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md +# Usage: tools/external_updater/updater.sh update external/rust/crates/slab +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "slab" description: "Pre-allocated storage for a uniform data type" third_party { - url { - type: HOMEPAGE - value: "https://crates.io/crates/slab" - } - url { - type: ARCHIVE - value: "https://static.crates.io/crates/slab/slab-0.4.8.crate" - } - version: "0.4.8" license_type: NOTICE last_upgrade_date { - year: 2023 - month: 3 - day: 6 + year: 2024 + month: 2 + day: 5 + } + homepage: "https://crates.io/crates/slab" + identifier { + type: "Archive" + value: "https://static.crates.io/crates/slab/slab-0.4.9.crate" + version: "0.4.9" } } @@ -129,7 +129,6 @@ use core::{fmt, mem, ops, slice}; /// See the [module documentation] for more details. /// /// [module documentation]: index.html -#[derive(Clone)] pub struct Slab<T> { // Chunk of memory entries: Vec<Entry<T>>, @@ -142,6 +141,25 @@ pub struct Slab<T> { next: usize, } +impl<T> Clone for Slab<T> +where + T: Clone, +{ + fn clone(&self) -> Self { + Self { + entries: self.entries.clone(), + len: self.len, + next: self.next, + } + } + + fn clone_from(&mut self, source: &Self) { + self.entries.clone_from(&source.entries); + self.len = source.len; + self.next = source.next; + } +} + impl<T> Default for Slab<T> { fn default() -> Self { Slab::new() diff --git a/tests/slab.rs b/tests/slab.rs index f446350..e18b40e 100644 --- a/tests/slab.rs +++ b/tests/slab.rs @@ -712,3 +712,24 @@ fn try_remove() { fn const_new() { static _SLAB: Slab<()> = Slab::new(); } + +#[test] +fn clone_from() { + let mut slab1 = Slab::new(); + let mut slab2 = Slab::new(); + for i in 0..5 { + slab1.insert(i); + slab2.insert(2 * i); + slab2.insert(2 * i + 1); + } + slab1.remove(1); + slab1.remove(3); + slab2.clone_from(&slab1); + + let mut iter2 = slab2.iter(); + assert_eq!(iter2.next(), Some((0, &0))); + assert_eq!(iter2.next(), Some((2, &2))); + assert_eq!(iter2.next(), Some((4, &4))); + assert_eq!(iter2.next(), None); + assert!(slab2.capacity() >= 10); +} |