From: Tony Cook Date: Mon, 31 Mar 2014 09:20:07 +0000 (+1100) Subject: [RT #92738] improve XS for i_io_read()/i_io_raw_read() X-Git-Tag: v0.99~15 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/3e00cb9049373242f21120e9aa3d33796753f83e [RT #92738] improve XS for i_io_read()/i_io_raw_read() Previously it would call sv_setpvn() which did all the right things, but we can avoid the sv_utf8_downgrade() and some of the other work done by sv_setpvn() with the new code. --- diff --git a/Imager.xs b/Imager.xs index ac804344..2b757fed 100644 --- a/Imager.xs +++ b/Imager.xs @@ -30,6 +30,10 @@ extern "C" { #include "imperl.h" +#ifndef SV_COW_DROP_PV +#define SV_COW_DROP_PV +#endif + /* Context object management @@ -1280,15 +1284,9 @@ i_io_raw_read(ig, buffer_sv, size) PPCODE: if (size <= 0) croak("size negative in call to i_io_raw_read()"); - /* prevent an undefined value warning if they supplied an - undef buffer. - Orginally conditional on !SvOK(), but this will prevent the - downgrade from croaking */ - sv_setpvn(buffer_sv, "", 0); -#ifdef SvUTF8 - if (SvUTF8(buffer_sv)) - sv_utf8_downgrade(buffer_sv, FALSE); -#endif + if (SvTHINKFIRST(buffer_sv)) + sv_force_normal_flags(buffer_sv, SV_COW_DROP_PV); + SvUPGRADE(buffer_sv, SVt_PV); buffer = SvGROW(buffer_sv, size+1); result = i_io_raw_read(ig, buffer, size); if (result >= 0) { @@ -1411,15 +1409,9 @@ i_io_read(ig, buffer_sv, size) PPCODE: if (size <= 0) croak("size negative in call to i_io_read()"); - /* prevent an undefined value warning if they supplied an - undef buffer. - Orginally conditional on !SvOK(), but this will prevent the - downgrade from croaking */ - sv_setpvn(buffer_sv, "", 0); -#ifdef SvUTF8 - if (SvUTF8(buffer_sv)) - sv_utf8_downgrade(buffer_sv, FALSE); -#endif + if (SvTHINKFIRST(buffer_sv)) + sv_force_normal_flags(buffer_sv, SV_COW_DROP_PV); + SvUPGRADE(buffer_sv, SVt_PV); buffer = SvGROW(buffer_sv, size+1); result = i_io_read(ig, buffer, size); if (result >= 0) {