Skip to content

Commit

Permalink
Perl_do_print: code readability improvements suggested in GH#22927
Browse files Browse the repository at this point in the history
  • Loading branch information
richardleach committed Jan 19, 2025
1 parent 80fe849 commit f0f3175
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions doio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,6 @@ Perl_do_print(pTHX_ SV *sv, PerlIO *fp)
return TRUE;
if (SvTYPE(sv) == SVt_IV && SvIOK(sv)) {
assert(!SvGMAGICAL(sv));
bool happy = TRUE;

/* Adapted from Perl_sv_2pv_flags */
const U32 isUIOK = SvIsUV(sv);
Expand All @@ -2221,16 +2220,14 @@ Perl_do_print(pTHX_ SV *sv, PerlIO *fp)
ptr = uiv_2buf(buf.arr, SvIVX(sv), tempuv, isUIOK, &ebuf);
len = ebuf - ptr;

if (len && (PerlIO_write(fp,ptr,len) == 0))
happy = FALSE;
return happy ? !PerlIO_error(fp) : FALSE;
bool happy = !(len && (PerlIO_write(fp,ptr,len) == 0));
return happy && !PerlIO_error(fp);
}
else {
STRLEN len;
/* Do this first to trigger any overloading. */
const char *tmps = SvPV_const(sv, len);
U8 *tmpbuf = NULL;
bool happy = TRUE;

if (PerlIO_isutf8(fp)) { /* If the stream is utf8 ... */
if (!SvUTF8(sv)) { /* Convert to utf8 if necessary */
Expand Down Expand Up @@ -2273,10 +2270,9 @@ Perl_do_print(pTHX_ SV *sv, PerlIO *fp)
* 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;
bool happy = !(len && (PerlIO_write(fp,tmps,len) == 0));
Safefree(tmpbuf);
return happy ? !PerlIO_error(fp) : FALSE;
return happy && !PerlIO_error(fp);
}
}

Expand Down

0 comments on commit f0f3175

Please sign in to comment.