fix macro
This commit is contained in:
@@ -19,10 +19,20 @@ pub fn perf(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
function.block.stmts.insert(0, parse_quote! {
|
||||
let __perf_start = std::time::Instant::now();
|
||||
});
|
||||
function.block.stmts.push(parse_quote! {
|
||||
|
||||
let timer_end = parse_quote! {
|
||||
unsafe {
|
||||
#counter_type::write_perf(#name, __perf_start.elapsed().as_micros());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if let Some(last_stmt) = function.block.stmts.last() {
|
||||
match last_stmt {
|
||||
syn::Stmt::Expr(_) => function.block.stmts.insert(function.block.stmts.len() - 1, timer_end),
|
||||
_ => function.block.stmts.push(timer_end),
|
||||
}
|
||||
} else {
|
||||
function.block.stmts.push(timer_end);
|
||||
}
|
||||
quote!(#function).into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user