diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 1999-08-19 12:49:41 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 1999-08-19 12:49:41 +0000 |
commit | 81e118e078828ea41cd654ee18f4193484a89cf3 (patch) | |
tree | 62637e08be5499f11f20df252b484d835c58e171 /mg.c | |
parent | 41bd693c38b93b50972065296573f26c13cc43d1 (diff) | |
download | perl-81e118e078828ea41cd654ee18f4193484a89cf3.tar.gz |
Removed duplicated code (in pp.c and mg.c) by introducing
do_vecget(). NOTE: the calling convention of do_vecset()
changes, too: the `offset' that is assigned to LvTARGOFF(TARG)
in pp_vec() is no more multiplied by `size' in pp_vec(),
the multiplication is now done in do_vecset().
Also fix a cpp thinko in change #4002.
p4raw-link: @4002 on //depot/cfgperl: 24db6c0d56fddf85ee587fc1cb1dbce678fa6a8c
p4raw-id: //depot/cfgperl@4004
Diffstat (limited to 'mg.c')
-rw-r--r-- | mg.c | 54 |
1 files changed, 1 insertions, 53 deletions
@@ -1361,65 +1361,13 @@ int Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg) { SV *lsv = LvTARG(sv); - unsigned char *s; - unsigned long retnum; - STRLEN lsvlen; - I32 len; - I32 offset; - I32 size; if (!lsv) { SvOK_off(sv); return 0; } - s = (unsigned char *) SvPV(lsv, lsvlen); - offset = LvTARGOFF(sv); - size = LvTARGLEN(sv); - len = (offset + size + 7) / 8; - - /* Copied from pp_vec() */ - - if (len > lsvlen) { - if (size <= 8) - retnum = 0; - else { - offset >>= 3; - if (size == 16) { - if (offset >= lsvlen) - retnum = 0; - else - retnum = (unsigned long) s[offset] << 8; - } - else if (size == 32) { - if (offset >= lsvlen) - retnum = 0; - else if (offset + 1 >= lsvlen) - retnum = (unsigned long) s[offset] << 24; - else if (offset + 2 >= lsvlen) - retnum = ((unsigned long) s[offset] << 24) + - ((unsigned long) s[offset + 1] << 16); - else - retnum = ((unsigned long) s[offset] << 24) + - ((unsigned long) s[offset + 1] << 16) + - (s[offset + 2] << 8); - } - } - } - else if (size < 8) - retnum = (s[offset >> 3] >> (offset & 7)) & ((1 << size) - 1); - else { - offset >>= 3; - if (size == 8) - retnum = s[offset]; - else if (size == 16) - retnum = ((unsigned long) s[offset] << 8) + s[offset+1]; - else if (size == 32) - retnum = ((unsigned long) s[offset] << 24) + - ((unsigned long) s[offset + 1] << 16) + - (s[offset + 2] << 8) + s[offset+3]; - } - sv_setuv(sv, (UV)retnum); + sv_setuv(sv, do_vecget(lsv, LvTARGOFF(sv), LvTARGLEN(sv))); return 0; } |