Skip to content

Commit ca96e0d

Browse files
author
Branislav Zahradník
committed
[parser] package - deduplicate coupled call sequence
Function combines call of original `package` and `package_version` when new namespace statement is detected. Instead of required three statements usage now consists of single function call.
1 parent c7aed9f commit ca96e0d

File tree

8 files changed

+357
-365
lines changed

8 files changed

+357
-365
lines changed

embed.fnc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,9 +2556,8 @@ px |OP * |op_unscope |NULLOK OP *o
25562556
ARdpx |OP * |op_wrap_finally|NN OP *block \
25572557
|NN OP *finally
25582558
: Used in perly.y
2559-
p |void |package |NN OP *o
2560-
: Used in perly.y
2561-
p |void |package_version|NN OP *v
2559+
dp |void |package |NN OP *o \
2560+
|NULLOK OP *v
25622561
Adp |void |packlist |NN SV *cat \
25632562
|NN const char *pat \
25642563
|NN const char *patend \

embed.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,7 @@
11171117
# define oopsAV(a) Perl_oopsAV(aTHX_ a)
11181118
# define oopsHV(a) Perl_oopsHV(aTHX_ a)
11191119
# define op_unscope(a) Perl_op_unscope(aTHX_ a)
1120-
# define package(a) Perl_package(aTHX_ a)
1121-
# define package_version(a) Perl_package_version(aTHX_ a)
1120+
# define package(a,b) Perl_package(aTHX_ a,b)
11221121
# define pad_add_weakref(a) Perl_pad_add_weakref(aTHX_ a)
11231122
# define pad_block_start(a) Perl_pad_block_start(aTHX_ a)
11241123
# define pad_fixup_inner_anons(a,b,c) Perl_pad_fixup_inner_anons(aTHX_ a,b,c)

op.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6100,7 +6100,7 @@ Perl_newBINOP(pTHX_ I32 type, I32 flags, OP *first, OP *last)
61006100
? 2 /* Otherwise, minimum of 2 hex digits */\
61016101
: NUM_HEX_CHARS(num)))))))
61026102

6103-
/* To make evident, Configure with `-DDEBUGGING`, build, run
6103+
/* To make evident, Configure with `-DDEBUGGING`, build, run
61046104
* `./perl -Ilib -Dy t/op/tr.t`
61056105
*/
61066106
void
@@ -8223,13 +8223,11 @@ Perl_newPVOP(pTHX_ I32 type, I32 flags, char *pv)
82238223
return CHECKOP(type, pvop);
82248224
}
82258225

8226-
void
8227-
Perl_package(pTHX_ OP *o)
8226+
STATIC void
8227+
S_set_package_name(pTHX_ OP *o)
82288228
{
82298229
SV *const sv = cSVOPo->op_sv;
82308230

8231-
PERL_ARGS_ASSERT_PACKAGE;
8232-
82338231
SAVEGENERICSV(PL_curstash);
82348232
save_item(PL_curstname);
82358233

@@ -8243,17 +8241,41 @@ Perl_package(pTHX_ OP *o)
82438241
op_free(o);
82448242
}
82458243

8246-
void
8247-
Perl_package_version( pTHX_ OP *v )
8244+
STATIC void
8245+
S_set_package_version( pTHX_ OP *v )
82488246
{
82498247
U32 savehints = PL_hints;
8250-
PERL_ARGS_ASSERT_PACKAGE_VERSION;
8248+
82518249
PL_hints &= ~HINT_STRICT_VARS;
82528250
sv_setsv( GvSV(gv_fetchpvs("VERSION", GV_ADDMULTI, SVt_PV)), cSVOPx(v)->op_sv );
82538251
PL_hints = savehints;
82548252
op_free(v);
82558253
}
82568254

8255+
/*
8256+
=for apidoc package
8257+
8258+
package ($name, $version)
8259+
8260+
Function sets current stash name and if not NULL, sets its C<$VERSION>.
8261+
8262+
It combines former C<package> and C<package_version> into single call.
8263+
8264+
Available since: v5.44
8265+
8266+
=cut
8267+
*/
8268+
8269+
void
8270+
Perl_package (pTHX_ OP *name, OP *version)
8271+
{
8272+
PERL_ARGS_ASSERT_PACKAGE;
8273+
8274+
S_set_package_name (aTHX_ name);
8275+
if (version)
8276+
S_set_package_version (aTHX_ version);
8277+
}
8278+
82578279
/* Extract the first two components of a "version" object as two 8bit integers
82588280
* and return them packed into a single U16 in the format of PL_prevailing_version.
82598281
* This function only ever has to cope with version objects already known
@@ -16846,7 +16868,7 @@ Perl_subsignature_append_positional(pTHX_ PADOFFSET padix, OPCODE defmode, OP *d
1684616868
signature->next_argix++;
1684716869

1684816870
if(!padix && !defexpr)
16849-
/* This param has no var and no defaulting expression. There's
16871+
/* This param has no var and no defaulting expression. There's
1685016872
* nothing else for us to do here.
1685116873
*/
1685216874
return;

0 commit comments

Comments
 (0)