Skip to content

Commit 4fd0d8a

Browse files
committed
Time::HiRes::stat() change ix from 0/1 to OP_STAT/OP_LSTAT, add $_[0] COW
-we dont need to map values 0/1 to OP_STAT/OP_LSTAT at runtime, it can be done once at CC time / BOOT:{} time -IDK why $_[0] is being duped, the pp_stat*() functions aren't supposed to modify incoming @_ args, but if we are going to dupe $_[0], atleast try to use COW semantics if available
1 parent 52db2ed commit 4fd0d8a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

dist/Time-HiRes/HiRes.xs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@
6464
# define SAVEOP() SAVEVPTR(PL_op)
6565
#endif
6666

67+
#if defined(SV_COW_SHARED_HASH_KEYS) && defined(SV_COW_OTHER_PVS)
68+
# define THR_newSVsv_cow(sv) newSVsv_flags((sv), SV_GMAGIC|SV_NOSTEAL|SV_COW_SHARED_HASH_KEYS|SV_COW_OTHER_PVS)
69+
#elif defined(SV_COW_SHARED_HASH_KEYS)
70+
# define THR_newSVsv_cow(sv) newSVsv_flags((sv), SV_GMAGIC|SV_NOSTEAL|SV_COW_SHARED_HASH_KEYS)
71+
#elif defined(SV_COW_OTHER_PVS)
72+
# define THR_newSVsv_cow(sv) newSVsv_flags((sv), SV_GMAGIC|SV_NOSTEAL|SV_COW_OTHER_PVS)
73+
#else
74+
# define THR_newSVsv_cow(sv) newSVsv_flags((sv), SV_GMAGIC|SV_NOSTEAL)
75+
#endif
76+
6777
#define IV_1E6 1000000
6878
#define IV_1E7 10000000
6979
#define IV_1E9 1000000000
@@ -1595,13 +1605,15 @@ PROTOTYPE: ;$
15951605
SSize_t nret;
15961606
SV* sv_arg;
15971607
SV** SPBASE;
1608+
U32 op_type = (U32)ix;
15981609
ALIAS:
1599-
Time::HiRes::lstat = 1
1610+
Time::HiRes::stat = OP_STAT
1611+
Time::HiRes::lstat = OP_LSTAT
16001612
PPCODE:
1601-
sv_arg = items == 1 ? ST(0) : DEFSV;
16021613
EXTEND(SP, 13);
1614+
sv_arg = items == 1 ? ST(0) : DEFSV;
16031615
/* XXX will pp_stat()/pp_lstat() really modify $_[0] ? */
1604-
PUSHs(sv_2mortal(newSVsv(sv_arg)));
1616+
PUSHs(sv_2mortal(THR_newSVsv_cow(sv_arg)));
16051617
PUTBACK;
16061618
ENTER;
16071619
PL_laststatval = -1;
@@ -1613,11 +1625,10 @@ PROTOTYPE: ;$
16131625
promise Zero(); and memset(); will inline. But this does. Now the CC can
16141626
detangle for us, what OP fields will get a 0/NULL, or our values. */
16151627
OP fakeop = {0};
1616-
U16 op_type = ix ? OP_LSTAT : OP_STAT;
16171628
fakeop.op_flags = gimme == G_LIST ? OPf_WANT_LIST :
16181629
gimme == G_SCALAR ? OPf_WANT_SCALAR : OPf_WANT_VOID; /* ILP */
16191630
ppaddr = PL_ppaddr[op_type];
1620-
fakeop.op_type = op_type;
1631+
fakeop.op_type = (U16)op_type;
16211632
fakeop.op_ppaddr = ppaddr; /* ILP */
16221633
PL_op = &fakeop;
16231634
(void)ppaddr(aTHX);

0 commit comments

Comments
 (0)