codegen: replace downcast_clone with more efficient mem::take
This commit is contained in:
parent
7506aee5c6
commit
6d11fdcd18
@ -356,16 +356,15 @@ impl ExportedFn {
|
||||
&syn::Type::Path(ref p) if p.path == str_type_path => {
|
||||
is_str_ref = true;
|
||||
quote_spanned!(arg_type.span()=>
|
||||
args[#i]
|
||||
.downcast_clone::<ImmutableString>()
|
||||
.unwrap())
|
||||
std::mem::take(args[#i])
|
||||
.clone().cast::<ImmutableString>())
|
||||
}
|
||||
_ => panic!("internal error: why wasn't this found earlier!?"),
|
||||
},
|
||||
_ => {
|
||||
is_str_ref = false;
|
||||
quote_spanned!(arg_type.span()=>
|
||||
args[#i].downcast_clone::<#arg_type>().unwrap())
|
||||
std::mem::take(args[#i]).clone().cast::<#arg_type>())
|
||||
}
|
||||
};
|
||||
|
||||
@ -768,7 +767,7 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 1usize), Position::none())));
|
||||
}
|
||||
let arg0 = args[0usize].downcast_clone::<usize>().unwrap();
|
||||
let arg0 = std::mem::take(args[0usize]).clone().cast::<usize>();
|
||||
Ok(Dynamic::from(do_something(arg0)))
|
||||
}
|
||||
|
||||
@ -808,7 +807,7 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 1usize), Position::none())));
|
||||
}
|
||||
let arg0 = args[0usize].downcast_clone::<usize>().unwrap();
|
||||
let arg0 = std::mem::take(args[0usize]).clone().cast::<usize>();
|
||||
Ok(Dynamic::from(do_something(arg0)))
|
||||
}
|
||||
|
||||
@ -845,8 +844,8 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 2usize), Position::none())));
|
||||
}
|
||||
let arg0 = args[0usize].downcast_clone::<usize>().unwrap();
|
||||
let arg1 = args[1usize].downcast_clone::<usize>().unwrap();
|
||||
let arg0 = std::mem::take(args[0usize]).clone().cast::<usize>();
|
||||
let arg1 = std::mem::take(args[1usize]).clone().cast::<usize>();
|
||||
Ok(Dynamic::from(add_together(arg0, arg1)))
|
||||
}
|
||||
|
||||
@ -891,7 +890,7 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 2usize), Position::none())));
|
||||
}
|
||||
let arg1 = args[1usize].downcast_clone::<usize>().unwrap();
|
||||
let arg1 = std::mem::take(args[1usize]).clone().cast::<usize>();
|
||||
let arg0: &mut _ = &mut args[0usize].write_lock::<usize>().unwrap();
|
||||
Ok(Dynamic::from(increment(arg0, arg1)))
|
||||
}
|
||||
@ -938,7 +937,7 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 1usize), Position::none())));
|
||||
}
|
||||
let arg0 = args[0usize].downcast_clone::<ImmutableString>().unwrap();
|
||||
let arg0 = std::mem::take(args[0usize]).clone().cast::<ImmutableString>();
|
||||
Ok(Dynamic::from(special_print(&arg0)))
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,7 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 1usize), Position::none())));
|
||||
}
|
||||
let arg0 = args[0usize].downcast_clone::<INT>().unwrap();
|
||||
let arg0 = std::mem::take(args[0usize]).clone().cast::<INT>();
|
||||
Ok(Dynamic::from(add_one_to(arg0)))
|
||||
}
|
||||
|
||||
@ -433,8 +433,8 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 2usize), Position::none())));
|
||||
}
|
||||
let arg0 = args[0usize].downcast_clone::<INT>().unwrap();
|
||||
let arg1 = args[1usize].downcast_clone::<INT>().unwrap();
|
||||
let arg0 = std::mem::take(args[0usize]).clone().cast::<INT>();
|
||||
let arg1 = std::mem::take(args[1usize]).clone().cast::<INT>();
|
||||
Ok(Dynamic::from(add_together(arg0, arg1)))
|
||||
}
|
||||
|
||||
@ -605,7 +605,7 @@ mod generate_tests {
|
||||
format!("wrong arg count: {} != {}",
|
||||
args.len(), 1usize), Position::none())));
|
||||
}
|
||||
let arg0 = args[0usize].downcast_clone::<ImmutableString>().unwrap();
|
||||
let arg0 = std::mem::take(args[0usize]).clone().cast::<ImmutableString>();
|
||||
Ok(Dynamic::from(print_out_to(&arg0)))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user