diff options
author | Nicholas Clark <nick@ccl4.org> | 2007-02-14 20:59:02 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2007-02-14 20:59:02 +0000 |
commit | e9950d3b0610b91bb9d19cb0918fe7e81505fd79 (patch) | |
tree | 2d7e500b8cd54c03dcd20c64dffca428b870b7ba /doio.c | |
parent | d56b30146911a1c03e38fbb1e59b6f4edf749c91 (diff) | |
download | perl-e9950d3b0610b91bb9d19cb0918fe7e81505fd79.tar.gz |
There's no need to special case SVt_NULL in the print code, as it's
only 0.01% of the cases called, and the call to SvPV_const() will
issue the same warning and return the same empty string result for us.
Unfortunately changing the switch statement to an if results in lots of
whitespace changes, hence this change appears much larger than it is.
p4raw-id: //depot/perl@30298
Diffstat (limited to 'doio.c')
-rw-r--r-- | doio.c | 57 |
1 files changed, 24 insertions, 33 deletions
@@ -1196,32 +1196,24 @@ bool Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) { dVAR; - register const char *tmps; - STRLEN len; - U8 *tmpbuf = NULL; - bool happy = TRUE; - /* assuming fp is checked earlier */ if (!sv) return TRUE; - switch (SvTYPE(sv)) { - case SVt_NULL: - if (ckWARN(WARN_UNINITIALIZED)) - report_uninit(sv); - return TRUE; - case SVt_IV: - if (SvIOK(sv)) { - assert(!SvGMAGICAL(sv)); - if (SvIsUV(sv)) - PerlIO_printf(fp, "%"UVuf, (UV)SvUVX(sv)); - else - PerlIO_printf(fp, "%"IVdf, (IV)SvIVX(sv)); - return !PerlIO_error(fp); - } - /* FALL THROUGH */ - default: + if (SvTYPE(sv) == SVt_IV && SvIOK(sv)) { + assert(!SvGMAGICAL(sv)); + if (SvIsUV(sv)) + PerlIO_printf(fp, "%"UVuf, (UV)SvUVX(sv)); + else + PerlIO_printf(fp, "%"IVdf, (IV)SvIVX(sv)); + return !PerlIO_error(fp); + } + else { + STRLEN len; /* Do this first to trigger any overloading. */ - tmps = SvPV_const(sv, len); + const char *tmps = SvPV_const(sv, len); + U8 *tmpbuf = NULL; + bool happy = TRUE; + if (PerlIO_isutf8(fp)) { if (!SvUTF8(sv)) { /* We don't modify the original scalar. */ @@ -1246,18 +1238,17 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) } } } - break; + /* To detect whether the process is about to overstep its + * filesize limit we would need getrlimit(). We could then + * also transparently raise the limit with setrlimit() -- + * but only until the system hard limit/the filesystem limit, + * at which we would get EPERM. Note that when using buffered + * io the write failure can be delayed until the flush/close. --jhi */ + if (len && (PerlIO_write(fp,tmps,len) == 0)) + happy = FALSE; + Safefree(tmpbuf); + return happy ? !PerlIO_error(fp) : FALSE; } - /* To detect whether the process is about to overstep its - * filesize limit we would need getrlimit(). We could then - * also transparently raise the limit with setrlimit() -- - * but only until the system hard limit/the filesystem limit, - * at which we would get EPERM. Note that when using buffered - * io the write failure can be delayed until the flush/close. --jhi */ - if (len && (PerlIO_write(fp,tmps,len) == 0)) - happy = FALSE; - Safefree(tmpbuf); - return happy ? !PerlIO_error(fp) : FALSE; } I32 |