Skip to content

Commit

Permalink
Remove accidental ::{{closure}} suffix from all profile_function
Browse files Browse the repository at this point in the history
…scopes

I inadvertantly added this in #165,
somehow not noticing it until now 🤦
  • Loading branch information
emilk committed Dec 11, 2023
1 parent 3a07ac9 commit 26bc34d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate

- [PR#175](https://github.com/EmbarkStudios/puffin/issues/175) Remove accidental `::{{closure}}` suffix from all `profile_function` scopes.

## [0.18.0] - 2023-11-21
## [0.17.1] - 2023-11-20

- [PR#165](https://github.com/EmbarkStudios/puffin/issues/165) Faster profiling, add line numbers, better paths, and better function names

## [0.17.1] - 2023-11-20 - YANKED

- Accidentally introduced a breaking change in [PR#165](https://github.com/EmbarkStudios/puffin/issues/165)

## [0.17.0] - 2023-09-28

- [PR#140](https://github.com/EmbarkStudios/puffin/issues/140) Remove imgui support for
Expand Down
9 changes: 8 additions & 1 deletion puffin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ pub fn type_name_of<T>(_: T) -> &'static str {
}

/// Returns the name of the calling function without a long module path prefix.
#[doc(hidden)]
#[macro_export]
macro_rules! current_function_name {
() => {{
Expand Down Expand Up @@ -825,7 +826,13 @@ macro_rules! profile_function {
// SAFETY: accessing the statics is safe because it is done in cojunction with `std::sync::Once``
let (function_name, location) = unsafe {
_INITITIALIZED.call_once(|| {
_FUNCTION_NAME = $crate::current_function_name!().leak();
let function_name = $crate::current_function_name!();

// We call `current_function_name` from a closure, so we need to strip that from the output.
// We only strip it once though, because if the user calls `profile_function!` from within a closure, they probably want to know it.
let function_name = function_name.strip_suffix("::{{closure}}").unwrap_or(function_name.as_ref());

_FUNCTION_NAME = function_name.to_owned().leak();
_LOCATION = format!("{}:{}", $crate::current_file_name!(), line!()).leak();
});
(_FUNCTION_NAME, _LOCATION)
Expand Down

0 comments on commit 26bc34d

Please sign in to comment.