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.insert(conn.handle(), None);
}
map.entry(conn.handle()).or_insert(None);
}
// 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>) {
let mut internal = self.0.lock().unwrap();
let scale = output.current_scale().fractional_scale();
if !internal.buffers.contains_key(&OrderedFloat(scale)) {
let buffer_size = internal
.size
let internal_size = internal.size;
internal.buffers.entry(OrderedFloat(scale)).or_insert({
let buffer_size = internal_size
.to_f64()
.to_buffer(scale, Transform::Normal)
.to_i32_round();
internal.buffers.insert(
OrderedFloat(scale),
(
MemoryRenderBuffer::new(
Fourcc::Argb8888,
buffer_size,
1,
Transform::Normal,
None,
),
None,
),
);
}
(
MemoryRenderBuffer::new(Fourcc::Argb8888, buffer_size, 1, Transform::Normal, None),
None,
)
});
internal.outputs.insert(output.clone());
}