Skip to content

Commit

Permalink
Try to simplify some pattern matching
Browse files Browse the repository at this point in the history
I'm not sure if the new version really is simpler, but at least I got
rid of an unwrap().

Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed Aug 17, 2024
1 parent 2695cd9 commit 9ee898e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions x11rb/src/cursor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,22 @@ fn create_render_cursor<C: Connection>(
let (width, height) = (to_u16(image.width), to_u16(image.height));

// Get a pixmap of the right size and a gc for it
let (pixmap, gc) = if storage.map(|(_, _, w, h)| (w, h)) == Some((width, height)) {
storage.map(|(pixmap, gc, _, _)| (pixmap, gc)).unwrap()
} else {
let (pixmap, gc) = if let Some((pixmap, gc, _, _)) = storage {
let _ = xproto::free_gc(conn, *gc)?;
let _ = xproto::free_pixmap(conn, *pixmap)?;
(*pixmap, *gc)
} else {
(conn.generate_id()?, conn.generate_id()?)
};
let _ = xproto::create_pixmap(conn, 32, pixmap, handle.root, width, height)?;
let _ = xproto::create_gc(conn, gc, pixmap, &Default::default())?;
let (pixmap, gc) = match *storage {
Some((pixmap, gc, w, h)) if (w, h) == (width, height) => (pixmap, gc),

Check warning on line 227 in x11rb/src/cursor/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb/src/cursor/mod.rs#L226-L227

Added lines #L226 - L227 were not covered by tests
_ => {
let (pixmap, gc) = if let Some((pixmap, gc, _, _)) = storage {
let _ = xproto::free_gc(conn, *gc)?;
let _ = xproto::free_pixmap(conn, *pixmap)?;
(*pixmap, *gc)

Check warning on line 232 in x11rb/src/cursor/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb/src/cursor/mod.rs#L229-L232

Added lines #L229 - L232 were not covered by tests
} else {
(conn.generate_id()?, conn.generate_id()?)

Check warning on line 234 in x11rb/src/cursor/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb/src/cursor/mod.rs#L234

Added line #L234 was not covered by tests
};
let _ = xproto::create_pixmap(conn, 32, pixmap, handle.root, width, height)?;
let _ = xproto::create_gc(conn, gc, pixmap, &Default::default())?;

Check warning on line 237 in x11rb/src/cursor/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb/src/cursor/mod.rs#L236-L237

Added lines #L236 - L237 were not covered by tests

*storage = Some((pixmap, gc, width, height));
(pixmap, gc)
*storage = Some((pixmap, gc, width, height));
(pixmap, gc)

Check warning on line 240 in x11rb/src/cursor/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb/src/cursor/mod.rs#L239-L240

Added lines #L239 - L240 were not covered by tests
}
};

let _ = xproto::put_image(
Expand Down

0 comments on commit 9ee898e

Please sign in to comment.