Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions crates/bevy_asset/src/io/gated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
use alloc::{boxed::Box, sync::Arc};
use async_channel::{Receiver, Sender};
use bevy_platform::{collections::HashMap, sync::RwLock};
use bevy_platform::{collections::hash_map::EntryRef, collections::HashMap, sync::RwLock};
use std::{path::Path, sync::PoisonError};

/// A "gated" reader that will prevent asset reads from returning until
Expand Down Expand Up @@ -32,9 +32,12 @@ impl GateOpener {
/// If multiple operations are expected, call `open` the expected number of calls.
pub fn open<P: AsRef<Path>>(&self, path: P) {
let mut gates = self.gates.write().unwrap_or_else(PoisonError::into_inner);
let gates = gates
.entry_ref(path.as_ref())
.or_insert_with(async_channel::unbounded);
let gates = match gates.entry_ref(path.as_ref()) {
EntryRef::Vacant(e) => {
e.insert_with_key(path.as_ref().into(), async_channel::unbounded())
}
EntryRef::Occupied(e) => e.into_mut(),
};
gates.0.send_blocking(()).unwrap();
}
}
Expand All @@ -58,9 +61,10 @@ impl<R: AssetReader> AssetReader for GatedReader<R> {
async fn read<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
let receiver = {
let mut gates = self.gates.write().unwrap_or_else(PoisonError::into_inner);
let gates = gates
.entry_ref(path.as_ref())
.or_insert_with(async_channel::unbounded);
let gates = match gates.entry_ref(path) {
EntryRef::Vacant(e) => e.insert_with_key(path.into(), async_channel::unbounded()),
EntryRef::Occupied(e) => e.into_mut(),
};
gates.1.clone()
};
receiver.recv().await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ spin = { version = "0.10.0", default-features = false, features = [
"barrier",
] }
foldhash = { version = "0.2.0", default-features = false }
hashbrown = { version = "0.16.1", features = [
hashbrown = { version = "0.17.1", features = [
"equivalent",
"raw-entry",
], optional = true, default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_platform/src/collections/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ where
/// ```rust
/// # use bevy_platform::collections::HashMap;
/// let mut map = HashMap::new();
/// # let mut map: HashMap<&'static str, usize> = map;
/// # let mut map: HashMap<String, usize> = map;
///
/// let value = map.entry_ref("foo").or_insert(0);
/// #
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bevy_platform = { path = "../bevy_platform", version = "0.19.0-dev", default-fea

# used by bevy-utils, but it also needs reflect impls
foldhash = { version = "0.2.0", default-features = false }
hashbrown = { version = "0.16.0", optional = true, default-features = false }
hashbrown = { version = "0.17.1", optional = true, default-features = false }

# other
erased-serde = { version = "0.4", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_shader/src/shader_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl<ShaderModule, RenderDevice> ShaderCache<ShaderModule, RenderDevice> {
let shader_module =
(self.load_module)(&self.device, shader_source, &shader.validate_shader)?;

entry.insert(Arc::new(shader_module))
entry.insert_with_key(shader_defs.into(), Arc::new(shader_module))
}
};

Expand Down
2 changes: 1 addition & 1 deletion tools/build-templated-pages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ toml_edit = { version = "0.25.1", default-features = false, features = [
tera = "1.15"
serde = { version = "1.0", features = ["derive"] }
bitflags = "2.3"
hashbrown = { version = "0.16.0", features = ["serde"] }
hashbrown = { version = "0.17.1", features = ["serde"] }

[lints]
workspace = true
10 changes: 8 additions & 2 deletions tools/build-templated-pages/src/examples.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::cmp::Ordering;
use std::fs::File;

use hashbrown::HashMap;
use hashbrown::hash_map::{EntryRef, HashMap};
use serde::Serialize;
use tera::{Context, Tera};
use toml_edit::{DocumentMut, Item};
Expand Down Expand Up @@ -111,7 +111,13 @@ pub(crate) fn check(what_to_run: Command) {
let examples_by_category: HashMap<Box<str>, Category> = examples
.into_iter()
.fold(HashMap::<Box<str>, Vec<Example>>::new(), |mut v, ex| {
v.entry_ref(ex.category.as_str()).or_default().push(ex);
match v.entry_ref(ex.category.as_str()) {
EntryRef::Vacant(e) => {
e.insert_with_key(ex.category.as_str().into(), Default::default())
}
EntryRef::Occupied(e) => e.into_mut(),
}
.push(ex);
v
})
.into_iter()
Expand Down
Loading