fix macro

This commit is contained in:
2021-11-03 01:56:34 +01:00
parent bee1b66b55
commit 9125878840
2 changed files with 14 additions and 2 deletions

View File

@@ -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()
}