mirror of
https://github.com/Perl/perl5.git
synced 2026-01-26 08:38:23 +00:00
Make croak() always expand to Perl_croak_nocontext()
Perl almost always opts for saving time over saving space. Hence, we have croak() that saves time at the expense of space, but needs thread context available; and croak_no_context() that doesn't need that, but takes extra time But, when we are about to die, time isn't that important. Even if we are doing eval after eval in a tight loop, the potential time savings of passing the thread context to Perl_croak is insignificant compared to the tear-down that follows. My claim then is that croak() never needed a thread context parameter to save a bit of time just before death. It is an optimization that isn't worth it. And having it do so required the invention of croak_nocontext(), and the extra cognitive load associated with two methods for the same task. This commit changes plain croak() to not use a thread context parameter. It and croak_nocontext() now behave identically. That means that going forward, people will likely choose croak() which requires less typing and occupies fewer columns on the screen, and they won't have to remember which form to use when.
This commit is contained in:
parent
e1e48325b2
commit
03f24b8a08
@ -86,7 +86,6 @@ my $item_flags_re = qr/[dD fF mM nN oO pT uU Wx;]/xx;
|
||||
|
||||
# This is a copy of the list in regen/embed.pl.
|
||||
my @have_compatibility_macros = qw(
|
||||
croak
|
||||
deb
|
||||
die
|
||||
form
|
||||
|
||||
@ -922,7 +922,7 @@ px |void |create_eval_scope \
|
||||
|NN SV **sp \
|
||||
|U32 flags
|
||||
: croak()'s first parm can be NULL. Otherwise, mod_perl breaks.
|
||||
Adfpr |void |croak |NULLOK const char *pat \
|
||||
AMdfpr |void |croak |NULLOK const char *pat \
|
||||
|...
|
||||
Tfpr |void |croak_caller |NULLOK const char *pat \
|
||||
|...
|
||||
|
||||
3
embed.h
3
embed.h
@ -29,7 +29,6 @@
|
||||
|
||||
#if !defined(MULTIPLICITY)
|
||||
/* undefined symbols, point them back at the usual ones */
|
||||
# define Perl_croak_nocontext Perl_croak
|
||||
# define Perl_deb_nocontext Perl_deb
|
||||
# define Perl_die_nocontext Perl_die
|
||||
# define Perl_form_nocontext Perl_form
|
||||
@ -78,7 +77,6 @@
|
||||
|
||||
# if defined(MULTIPLICITY) && !defined(PERL_NO_SHORT_NAMES) && \
|
||||
!defined(PERL_WANT_VARARGS)
|
||||
# define croak Perl_croak_nocontext
|
||||
# define deb Perl_deb_nocontext
|
||||
# define die Perl_die_nocontext
|
||||
# define form Perl_form_nocontext
|
||||
@ -914,7 +912,6 @@
|
||||
# endif /* defined(MULTIPLICITY) */
|
||||
# if !defined(MULTIPLICITY) || defined(PERL_CORE) || \
|
||||
defined(PERL_WANT_VARARGS)
|
||||
# define croak(...) Perl_croak(aTHX_ __VA_ARGS__)
|
||||
# define deb(...) Perl_deb(aTHX_ __VA_ARGS__)
|
||||
# define die(...) Perl_die(aTHX_ __VA_ARGS__)
|
||||
# define form(...) Perl_form(aTHX_ __VA_ARGS__)
|
||||
|
||||
@ -41,7 +41,6 @@ BEGIN {
|
||||
# N.B. If you change this list, update the copy in autodoc.pl. This is likely
|
||||
# to never happen, so not worth coding automatic synchronization.
|
||||
my @have_compatibility_macros = qw(
|
||||
croak
|
||||
deb
|
||||
die
|
||||
form
|
||||
|
||||
7
util.c
7
util.c
@ -1912,10 +1912,9 @@ error message from arguments. If you want to throw a non-string object,
|
||||
or build an error message in an SV yourself, it is preferable to use
|
||||
the C<L</croak_sv>> function, which does not involve clobbering C<ERRSV>.
|
||||
|
||||
The two forms differ only in that C<croak_nocontext> does not take a thread
|
||||
context (C<aTHX>) parameter. It is usually preferred as it takes up fewer
|
||||
bytes of code than plain C<Perl_croak>, and time is rarely a critical resource
|
||||
when you are about to throw an exception.
|
||||
The reasons for the existence of C<croak_nocontext> are no longer applicable.
|
||||
croak() can now be used in all circumstances. C<Perl_croak_nocontext> might be
|
||||
useful when compiling with C<PERL_NO_SHORT_NAMES>.
|
||||
|
||||
=cut
|
||||
*/
|
||||
|
||||
9
util.h
9
util.h
@ -11,6 +11,15 @@
|
||||
#ifndef PERL_UTIL_H_
|
||||
#define PERL_UTIL_H_
|
||||
|
||||
/* Calling Perl_croak_nocontext instead of plain Perl_croak is one less
|
||||
* argument to pass under threads, so each instance takes up fewer bytes (but
|
||||
* the nocontext function has to derive the thread context itself, taking more
|
||||
* time). We trade time for less space here, because time is rarely a
|
||||
* critical resource when you are about to throw an exception. */
|
||||
#define croak(...) Perl_croak_nocontext(__VA_ARGS__)
|
||||
#ifndef MULTIPLICITY
|
||||
# define Perl_croak_nocontext Perl_croak
|
||||
#endif
|
||||
|
||||
#ifdef VMS
|
||||
# define PERL_FILE_IS_ABSOLUTE(f) \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user