#31820 - Utilize if..let instead of single match branch

This commit is contained in:
dileepb 2016-02-23 21:18:07 +05:30
parent 6ffd7cd166
commit fbfe70e6ab
9 changed files with 28 additions and 42 deletions

View file

@ -226,9 +226,8 @@ fn symbol_hash<'tcx>(tcx: &ty::ctxt<'tcx>,
}
fn get_symbol_hash<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> String {
match ccx.type_hashcodes().borrow().get(&t) {
Some(h) => return h.to_string(),
None => {}
if let Some(h) = ccx.type_hashcodes().borrow().get(&t) {
return h.to_string()
}
let mut symbol_hasher = ccx.symbol_hasher().borrow_mut();
@ -315,9 +314,8 @@ pub fn mangle<PI: Iterator<Item=InternedString>>(path: PI, hash: Option<&str>) -
push(&mut n, &data);
}
match hash {
Some(s) => push(&mut n, s),
None => {}
if let Some(s) = hash {
push(&mut n, s)
}
n.push('E'); // End name-sequence.

View file

@ -150,9 +150,8 @@ impl Drop for _InsnCtxt {
pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
debug!("new InsnCtxt: {}", s);
TASK_LOCAL_INSN_KEY.with(|slot| {
match slot.borrow_mut().as_mut() {
Some(ctx) => ctx.push(s),
None => {}
if let Some(ctx) = slot.borrow_mut().as_mut() {
ctx.push(s)
}
});
_InsnCtxt {
@ -198,9 +197,8 @@ fn get_extern_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
name: &str,
did: DefId)
-> ValueRef {
match ccx.externs().borrow().get(name) {
Some(n) => return *n,
None => (),
if let Some(n) = ccx.externs().borrow().get(name) {
return *n;
}
let f = declare::declare_rust_fn(ccx, name, fn_ty);
@ -238,9 +236,8 @@ pub fn get_extern_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
-> ValueRef {
let name = ccx.sess().cstore.item_symbol(did);
let ty = type_of(ccx, t);
match ccx.externs().borrow_mut().get(&name) {
Some(n) => return *n,
None => (),
if let Some(n) = ccx.externs().borrow_mut().get(&name) {
return *n;
}
// FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow?
// FIXME(nagisa): investigate whether it can be changed into define_global
@ -2755,9 +2752,8 @@ fn contains_null(s: &str) -> bool {
pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
debug!("get_item_val(id=`{}`)", id);
match ccx.item_vals().borrow().get(&id).cloned() {
Some(v) => return v,
None => {}
if let Some(v) = ccx.item_vals().borrow().get(&id).cloned() {
return v;
}
let item = ccx.tcx().map.get(id);

View file

@ -947,9 +947,8 @@ pub fn C_u8(ccx: &CrateContext, i: u8) -> ValueRef {
// our boxed-and-length-annotated strings.
pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef {
unsafe {
match cx.const_cstr_cache().borrow().get(&s) {
Some(&llval) => return llval,
None => ()
if let Some(&llval) = cx.const_cstr_cache().borrow().get(&s) {
return llval;
}
let sc = llvm::LLVMConstStringInContext(cx.llcx(),

View file

@ -182,9 +182,8 @@ pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>)
// recursive types. For example, enum types rely on this behavior.
pub fn sizing_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type {
match cx.llsizingtypes().borrow().get(&t).cloned() {
Some(t) => return t,
None => ()
if let Some(t) = cx.llsizingtypes().borrow().get(&t).cloned() {
return t;
}
debug!("sizing_type_of {:?}", t);
@ -317,9 +316,8 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Type {
/// NB: If you update this, be sure to update `sizing_type_of()` as well.
pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type {
// Check the cache.
match cx.lltypes().borrow().get(&t) {
Some(&llty) => return llty,
None => ()
if let Some(&llty) = cx.lltypes().borrow().get(&t) {
return llty;
}
debug!("type_of {:?}", t);