Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding boolean overload that just returns true #23

Closed
miyagawa opened this issue Jan 5, 2024 · 1 comment
Closed

Consider adding boolean overload that just returns true #23

miyagawa opened this issue Jan 5, 2024 · 1 comment

Comments

@miyagawa
Copy link

miyagawa commented Jan 5, 2024

re plack/Plack#697

if ($trace && some_other_condition()) {
  $trace->as_string;
}

this code looks as if $trace->as_string doesn't get called if some_other_condition() is false, or just once if the condition is true. But actually, the first if ($trace) triggers as_string due to the string overloading, and how perl's overload automatically uses the string value for boolean check. As a result, $trace->as_string is called one extra time which could cause some slow down in the app when the stacktrace is huge.

Consider adding bool => sub { 1 } to the overload list to avoid this. I've worked around in the caller code to change the if statement to if (ref $trace) for now.

@autarch
Copy link
Member

autarch commented Jan 8, 2024

Thanks for the suggestion. This is done in v2.05.

@autarch autarch closed this as completed Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants