Use map.entry().or_insert() instead of map.contains_key() and map.insert()

This commit is contained in:
julianbraha 2024-08-29 14:10:21 +01:00 committed by Victoria Brekenfeld
parent 536484e9da
commit 2e2356ab5f
2 changed files with 12 additions and 20 deletions

View file

@ -69,9 +69,7 @@ pub fn display_configuration(
} }
} }
if !map.contains_key(&conn.handle()) { map.entry(conn.handle()).or_insert(None);
map.insert(conn.handle(), None);
}
} }
// And then cleanup // And then cleanup

View file

@ -765,26 +765,20 @@ impl<P: Program + Send + 'static> SpaceElement for IcedElement<P> {
fn output_enter(&self, output: &Output, _overlap: Rectangle<i32, Logical>) { fn output_enter(&self, output: &Output, _overlap: Rectangle<i32, Logical>) {
let mut internal = self.0.lock().unwrap(); let mut internal = self.0.lock().unwrap();
let scale = output.current_scale().fractional_scale(); let scale = output.current_scale().fractional_scale();
if !internal.buffers.contains_key(&OrderedFloat(scale)) {
let buffer_size = internal let internal_size = internal.size;
.size internal.buffers.entry(OrderedFloat(scale)).or_insert({
let buffer_size = internal_size
.to_f64() .to_f64()
.to_buffer(scale, Transform::Normal) .to_buffer(scale, Transform::Normal)
.to_i32_round(); .to_i32_round();
internal.buffers.insert(
OrderedFloat(scale), (
( MemoryRenderBuffer::new(Fourcc::Argb8888, buffer_size, 1, Transform::Normal, None),
MemoryRenderBuffer::new( None,
Fourcc::Argb8888, )
buffer_size, });
1,
Transform::Normal,
None,
),
None,
),
);
}
internal.outputs.insert(output.clone()); internal.outputs.insert(output.clone());
} }