From: Nicholas Clark Date: Tue, 7 Feb 2006 14:11:42 +0000 (+0000) Subject: pp_hex can be implemented trivially by pp_oct, making pp_hex a mathom. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=daa2adfd3a5f888cb1c60469c1ec42e215d455bb;p=p5sagit%2Fp5-mst-13.2.git pp_hex can be implemented trivially by pp_oct, making pp_hex a mathom. p4raw-id: //depot/perl@27119 --- diff --git a/mathoms.c b/mathoms.c index 261abe3..f1f20b2 100644 --- a/mathoms.c +++ b/mathoms.c @@ -1044,6 +1044,11 @@ PP(pp_rindex) return pp_index(); } +PP(pp_hex) +{ + return pp_oct(); +} + U8 * Perl_uvuni_to_utf8(pTHX_ U8 *d, UV uv) { diff --git a/opcode.h b/opcode.h index 5b73eb6..4541421 100644 --- a/opcode.h +++ b/opcode.h @@ -892,7 +892,7 @@ EXT Perl_ppaddr_t PL_ppaddr[] /* or perlvars.h */ MEMBER_TO_FPTR(Perl_pp_log), MEMBER_TO_FPTR(Perl_pp_sqrt), MEMBER_TO_FPTR(Perl_pp_int), - MEMBER_TO_FPTR(Perl_pp_hex), + MEMBER_TO_FPTR(Perl_pp_oct), /* Perl_pp_hex */ MEMBER_TO_FPTR(Perl_pp_oct), MEMBER_TO_FPTR(Perl_pp_abs), MEMBER_TO_FPTR(Perl_pp_length), diff --git a/opcode.pl b/opcode.pl index c548f7b..b1c50b9 100755 --- a/opcode.pl +++ b/opcode.pl @@ -80,6 +80,7 @@ my @raw_alias = ( Perl_pp_sle => [qw(slt sgt sge)], Perl_pp_print => ['say'], Perl_pp_index => ['rindex'], + Perl_pp_oct => ['hex'], ); while (my ($func, $names) = splice @raw_alias, 0, 2) { diff --git a/pp.c b/pp.c index 01dac5c..7789120 100644 --- a/pp.c +++ b/pp.c @@ -2821,37 +2821,6 @@ PP(pp_abs) RETURN; } - -PP(pp_hex) -{ - dVAR; dSP; dTARGET; - const char *tmps; - I32 flags = PERL_SCAN_ALLOW_UNDERSCORES; - STRLEN len; - NV result_nv; - UV result_uv; - SV* const sv = POPs; - - tmps = (SvPV_const(sv, len)); - if (DO_UTF8(sv)) { - /* If Unicode, try to downgrade - * If not possible, croak. */ - SV* const tsv = sv_2mortal(newSVsv(sv)); - - SvUTF8_on(tsv); - sv_utf8_downgrade(tsv, FALSE); - tmps = SvPV_const(tsv, len); - } - result_uv = grok_hex (tmps, &len, &flags, &result_nv); - if (flags & PERL_SCAN_GREATER_THAN_UV_MAX) { - XPUSHn(result_nv); - } - else { - XPUSHu(result_uv); - } - RETURN; -} - PP(pp_oct) { dVAR; dSP; dTARGET; @@ -2872,12 +2841,17 @@ PP(pp_oct) sv_utf8_downgrade(tsv, FALSE); tmps = SvPV_const(tsv, len); } + if (PL_op->op_type == OP_HEX) + goto hex; + while (*tmps && len && isSPACE(*tmps)) tmps++, len--; if (*tmps == '0') tmps++, len--; - if (*tmps == 'x') + if (*tmps == 'x') { + hex: result_uv = grok_hex (tmps, &len, &flags, &result_nv); + } else if (*tmps == 'b') result_uv = grok_bin (tmps, &len, &flags, &result_nv); else