From 5f10092995d8c800fece8463e330d64c9a558768 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 14 Nov 2014 17:17:40 -0500 Subject: [PATCH] embedding: convert callback Option<> matching to map() --- ports/cef/core.rs | 16 +++------------- ports/cef/string.rs | 21 +++------------------ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/ports/cef/core.rs b/ports/cef/core.rs index 44533b89661..16558b43bd8 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -23,22 +23,12 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t, } unsafe { command_line_init((*args).argc, (*args).argv); - match (*application).get_browser_process_handler { - Some(cb) => { + (*application).get_browser_process_handler.map(|cb| { let handler = cb(application); if handler.is_not_null() { - match (*handler).on_context_initialized { - Some(hcb) => { - hcb(handler); - return 1; - }, - None => { return 1; } - } + (*handler).on_context_initialized.map(|hcb| hcb(handler)); } - return 1; - }, - None => { return 1; } - } + }); } return 1 } diff --git a/ports/cef/string.rs b/ports/cef/string.rs index fe94b7bc750..9f3baac8f10 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -52,12 +52,7 @@ pub extern "C" fn cef_string_userfree_utf16_free(cs: *mut cef_string_userfree_ut #[no_mangle] pub extern "C" fn cef_string_utf8_clear(cs: *mut cef_string_utf8_t) { unsafe { - match (*cs).dtor { - Some(dtor) => { - dtor((*cs).str); - }, - None => () - }; + (*cs).dtor.map(|dtor| dtor((*cs).str)); (*cs).length = 0; (*cs).str = 0 as *mut u8; (*cs).dtor = mem::transmute(0 as *const u8); @@ -136,12 +131,7 @@ pub extern "C" fn cef_string_utf16_to_utf8(src: *const u16, src_len: size_t, out #[no_mangle] pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) { unsafe { - match (*cs).dtor { - Some(dtor) => { - dtor((*cs).str); - }, - None => () - }; + (*cs).dtor.map(|dtor| dtor((*cs).str)); (*cs).length = 0; (*cs).str = 0 as *mut c_ushort; (*cs).dtor = mem::transmute(0 as *const u8); @@ -196,12 +186,7 @@ pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const c #[no_mangle] pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) { unsafe { - match (*cs).dtor { - Some(dtor) => { - dtor((*cs).str); - }, - None => () - }; + (*cs).dtor.map(|dtor| dtor((*cs).str)); (*cs).length = 0; (*cs).str = 0 as *mut wchar_t; (*cs).dtor = mem::transmute(0 as *const u8);