RETURN;
}
-PP(pp_scalar)
-{
- return NORMAL;
-}
-
/* Pushy stuff. */
PP(pp_padav)
if (SvMAGICAL(TARG)) {
U32 i;
for (i=0; i < (U32)maxarg; i++) {
- SV ** const svp = av_fetch((AV*)TARG, i, FALSE);
+ SV * const * const svp = av_fetch((AV*)TARG, i, FALSE);
SP[i+1] = (svp) ? *svp : &PL_sv_undef;
}
}
GV *gv;
if (cUNOP->op_targ) {
STRLEN len;
- SV *namesv = PAD_SV(cUNOP->op_targ);
- const char *name = SvPV(namesv, len);
+ SV * const namesv = PAD_SV(cUNOP->op_targ);
+ const char * const name = SvPV(namesv, len);
gv = (GV*)NEWSV(0,0);
gv_init(gv, CopSTASH(PL_curcop), name, len, 0);
}
else {
- const char *name = CopSTASHPV(PL_curcop);
+ const char * const name = CopSTASHPV(PL_curcop);
gv = newGVgen(name);
}
if (SvTYPE(sv) < SVt_RV)
if (SvROK(sv))
goto wasref;
}
+ if (PL_op->op_private & HINT_STRICT_REFS) {
+ if (SvOK(sv))
+ DIE(aTHX_ PL_no_symref_sv, sv, "a SCALAR");
+ else
+ DIE(aTHX_ PL_no_usym, "a SCALAR");
+ }
if (!SvOK(sv)) {
- if (PL_op->op_flags & OPf_REF ||
- PL_op->op_private & HINT_STRICT_REFS)
+ if (PL_op->op_flags & OPf_REF)
DIE(aTHX_ PL_no_usym, "a SCALAR");
if (ckWARN(WARN_UNINITIALIZED))
report_uninit(sv);
}
}
else {
- if (PL_op->op_private & HINT_STRICT_REFS)
- DIE(aTHX_ PL_no_symref_sv, sv, "a SCALAR");
gv = (GV*)gv_fetchsv(sv, TRUE, SVt_PV);
}
}
ret = &PL_sv_undef;
if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) {
- const char *s = SvPVX_const(TOPs);
+ const char * const s = SvPVX_const(TOPs);
if (strnEQ(s, "CORE::", 6)) {
const int code = keyword(s + 6, SvCUR(TOPs) - 6);
if (code < 0) { /* Overridable. */
while (MARK < SP)
do_chop(TARG, *++MARK);
SP = ORIGMARK;
- PUSHTARG;
+ XPUSHTARG;
RETURN;
}
while (SP > MARK)
count += do_chomp(POPs);
- PUSHi(count);
+ XPUSHi(count);
RETURN;
}
-PP(pp_defined)
-{
- dSP;
- register SV* const sv = POPs;
-
- if (!sv || !SvANY(sv))
- RETPUSHNO;
- switch (SvTYPE(sv)) {
- case SVt_PVAV:
- if (AvMAX(sv) >= 0 || SvGMAGICAL(sv)
- || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
- RETPUSHYES;
- break;
- case SVt_PVHV:
- if (HvARRAY(sv) || SvGMAGICAL(sv)
- || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
- RETPUSHYES;
- break;
- case SVt_PVCV:
- if (CvROOT(sv) || CvXSUB(sv))
- RETPUSHYES;
- break;
- default:
- SvGETMAGIC(sv);
- if (SvOK(sv))
- RETPUSHYES;
- }
- RETPUSHNO;
-}
-
PP(pp_undef)
{
dSP;
case SVt_PVFM:
{
/* let user-undef'd sub keep its identity */
- GV* gv = CvGV((CV*)sv);
+ GV* const gv = CvGV((CV*)sv);
cv_undef((CV*)sv);
CvGV((CV*)sv) = gv;
}
if (!left_neg) {
left = SvUVX(POPs);
} else {
- IV aiv = SvIVX(POPs);
+ const IV aiv = SvIVX(POPs);
if (aiv >= 0) {
left = aiv;
left_neg = FALSE; /* effectively it's a UV now */
else
count = uv;
} else {
- IV iv = SvIV(sv);
+ const IV iv = SvIV(sv);
if (iv < 0)
count = 0;
else
count = SvIVx(sv);
if (GIMME == G_ARRAY && PL_op->op_private & OPpREPEAT_DOLIST) {
dMARK;
- I32 items = SP - MARK;
- I32 max;
- static const char oom_list_extend[] =
- "Out of memory during list extend";
+ static const char oom_list_extend[] = "Out of memory during list extend";
+ const I32 items = SP - MARK;
+ const I32 max = items * count;
- max = items * count;
MEM_WRAP_CHECK_1(max, SV*, oom_list_extend);
/* Did the max computation overflow? */
if (items > 0 && max > 0 && (max < items || max < count))
SP -= items;
}
else { /* Note: mark already snarfed by pp_list */
- SV *tmpstr = POPs;
+ SV * const tmpstr = POPs;
STRLEN len;
bool isutf;
static const char oom_string_extend[] =
{
const IV shift = POPi;
if (PL_op->op_private & HINT_INTEGER) {
- IV i = TOPi;
+ const IV i = TOPi;
SETi(i >> shift);
}
else {
- UV u = TOPu;
+ const UV u = TOPu;
SETu(u >> shift);
}
RETURN;
if (SvIOK(TOPs)) {
SvIV_please(TOPm1s);
if (SvIOK(TOPm1s)) {
- bool auvok = SvUOK(TOPm1s);
- bool buvok = SvUOK(TOPs);
+ const bool auvok = SvUOK(TOPm1s);
+ const bool buvok = SvUOK(TOPs);
if (auvok == buvok) { /* ## IV == IV or UV == UV ## */
/* Casting IV to UV before comparison isn't going to matter
dSP; dTARGET; tryAMAGICbin(ncmp,0);
#ifndef NV_PRESERVES_UV
if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
- UV right = PTR2UV(SvRV(POPs));
- UV left = PTR2UV(SvRV(TOPs));
+ const UV right = PTR2UV(SvRV(POPs));
+ const UV left = PTR2UV(SvRV(TOPs));
SETi((left > right) - (left < right));
RETURN;
}
}
}
-PP(pp_slt)
+PP(pp_sle)
{
- dSP; tryAMAGICbinSET(slt,0);
- {
- dPOPTOPssrl;
- const int cmp = (IN_LOCALE_RUNTIME
- ? sv_cmp_locale(left, right)
- : sv_cmp(left, right));
- SETs(boolSV(cmp < 0));
- RETURN;
- }
-}
+ dSP;
-PP(pp_sgt)
-{
- dSP; tryAMAGICbinSET(sgt,0);
- {
- dPOPTOPssrl;
- const int cmp = (IN_LOCALE_RUNTIME
- ? sv_cmp_locale(left, right)
- : sv_cmp(left, right));
- SETs(boolSV(cmp > 0));
- RETURN;
- }
-}
+ int amg_type = sle_amg;
+ int multiplier = 1;
+ int rhs = 1;
-PP(pp_sle)
-{
- dSP; tryAMAGICbinSET(sle,0);
- {
- dPOPTOPssrl;
- const int cmp = (IN_LOCALE_RUNTIME
- ? sv_cmp_locale(left, right)
- : sv_cmp(left, right));
- SETs(boolSV(cmp <= 0));
- RETURN;
+ switch (PL_op->op_type) {
+ case OP_SLT:
+ amg_type = slt_amg;
+ /* cmp < 0 */
+ rhs = 0;
+ break;
+ case OP_SGT:
+ amg_type = sgt_amg;
+ /* cmp > 0 */
+ multiplier = -1;
+ rhs = 0;
+ break;
+ case OP_SGE:
+ amg_type = sge_amg;
+ /* cmp >= 0 */
+ multiplier = -1;
+ break;
}
-}
-PP(pp_sge)
-{
- dSP; tryAMAGICbinSET(sge,0);
+ tryAMAGICbinSET_var(amg_type,0);
{
dPOPTOPssrl;
const int cmp = (IN_LOCALE_RUNTIME
? sv_cmp_locale(left, right)
: sv_cmp(left, right));
- SETs(boolSV(cmp >= 0));
+ SETs(boolSV(cmp * multiplier < rhs));
RETURN;
}
}
PP(pp_srand)
{
dSP;
- UV anum;
- if (MAXARG < 1)
- anum = seed();
- else
- anum = POPu;
+ const UV anum = (MAXARG < 1) ? seed() : POPu;
(void)seedDrand01((Rand_seed_t)anum);
PL_srand_called = TRUE;
EXTEND(SP, 1);
PP(pp_length)
{
dSP; dTARGET;
- SV *sv = TOPs;
+ SV * const sv = TOPs;
if (DO_UTF8(sv))
SETi(sv_len_utf8(sv));
dSP; dMARK; dORIGMARK; dTARGET;
do_sprintf(TARG, SP-MARK, MARK+1);
TAINT_IF(SvTAINTED(TARG));
- if (DO_UTF8(*(MARK+1)))
- SvUTF8_on(TARG);
SP = ORIGMARK;
PUSHTARG;
RETURN;
SV *sv = TOPs;
const U8 *s;
STRLEN slen;
+ const int op_type = PL_op->op_type;
SvGETMAGIC(sv);
if (DO_UTF8(sv) &&
STRLEN tculen;
utf8_to_uvchr(s, &ulen);
- toTITLE_utf8(s, tmpbuf, &tculen);
- utf8_to_uvchr(tmpbuf, 0);
+ if (op_type == OP_UCFIRST) {
+ toTITLE_utf8(s, tmpbuf, &tculen);
+ } else {
+ toLOWER_utf8(s, tmpbuf, &tculen);
+ }
- if (!SvPADTMP(sv) || SvREADONLY(sv)) {
+ if (!SvPADTMP(sv) || SvREADONLY(sv) || ulen != tculen) {
dTARGET;
/* slen is the byte length of the whole SV.
* ulen is the byte length of the original Unicode character
* stored as UTF-8 at s.
- * tculen is the byte length of the freshly titlecased
- * Unicode character stored as UTF-8 at tmpbuf.
- * We first set the result to be the titlecased character,
- * and then append the rest of the SV data. */
+ * tculen is the byte length of the freshly titlecased (or
+ * lowercased) Unicode character stored as UTF-8 at tmpbuf.
+ * We first set the result to be the titlecased (/lowercased)
+ * character, and then append the rest of the SV data. */
sv_setpvn(TARG, (char*)tmpbuf, tculen);
if (slen > ulen)
sv_catpvn(TARG, (char*)(s + ulen), slen - ulen);
if (IN_LOCALE_RUNTIME) {
TAINT;
SvTAINTED_on(sv);
- *s1 = toUPPER_LC(*s1);
+ *s1 = (op_type == OP_UCFIRST)
+ ? toUPPER_LC(*s1) : toLOWER_LC(*s1);
}
else
- *s1 = toUPPER(*s1);
- }
- }
- SvSETMAGIC(sv);
- RETURN;
-}
-
-PP(pp_lcfirst)
-{
- dSP;
- SV *sv = TOPs;
- const U8 *s;
- STRLEN slen;
-
- SvGETMAGIC(sv);
- if (DO_UTF8(sv) &&
- (s = (const U8*)SvPV_nomg_const(sv, slen)) && slen &&
- UTF8_IS_START(*s)) {
- STRLEN ulen;
- U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
- U8 *tend;
- UV uv;
-
- toLOWER_utf8(s, tmpbuf, &ulen);
- uv = utf8_to_uvchr(tmpbuf, 0);
- tend = uvchr_to_utf8(tmpbuf, uv);
-
- if (!SvPADTMP(sv) || (STRLEN)(tend - tmpbuf) != ulen || SvREADONLY(sv)) {
- dTARGET;
- sv_setpvn(TARG, (char*)tmpbuf, tend - tmpbuf);
- if (slen > ulen)
- sv_catpvn(TARG, (char*)(s + ulen), slen - ulen);
- SvUTF8_on(TARG);
- SETs(TARG);
- }
- else {
- s = (U8*)SvPV_force_nomg(sv, slen);
- Copy(tmpbuf, s, ulen, U8);
- }
- }
- else {
- U8 *s1;
- if (!SvPADTMP(sv) || SvREADONLY(sv)) {
- dTARGET;
- SvUTF8_off(TARG); /* decontaminate */
- sv_setsv_nomg(TARG, sv);
- sv = TARG;
- SETs(sv);
- }
- s1 = (U8*)SvPV_force_nomg(sv, slen);
- if (*s1) {
- if (IN_LOCALE_RUNTIME) {
- TAINT;
- SvTAINTED_on(sv);
- *s1 = toLOWER_LC(*s1);
- }
- else
- *s1 = toLOWER(*s1);
+ *s1 = (op_type == OP_UCFIRST) ? toUPPER(*s1) : toLOWER(*s1);
}
}
SvSETMAGIC(sv);
if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) {
/* If the eventually required minimum size outgrows
* the available space, we need to grow. */
- UV o = d - (U8*)SvPVX_const(TARG);
+ const UV o = d - (U8*)SvPVX_const(TARG);
/* If someone uppercases one million U+03B0s we
* SvGROW() one million times. Or we could try
if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) {
/* If the eventually required minimum size outgrows
* the available space, we need to grow. */
- UV o = d - (U8*)SvPVX_const(TARG);
+ const UV o = d - (U8*)SvPVX_const(TARG);
/* If someone lowercases one million U+0130s we
* SvGROW() one million times. Or we could try
RETURN;
}
-PP(pp_values)
-{
- return do_kv();
-}
-
-PP(pp_keys)
-{
- return do_kv();
-}
-
PP(pp_delete)
{
dSP;
if (PL_op->op_private & OPpEXISTS_SUB) {
GV *gv;
- SV *sv = POPs;
+ SV * const sv = POPs;
CV * const cv = sv_2cv(sv, &hv, &gv, FALSE);
if (cv)
RETPUSHYES;
else if (gimme != G_ARRAY)
ary = GvAVn(PL_defgv);
else
- ary = Nullav;
+ ary = NULL;
if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) {
realarray = 1;
PUTBACK;