Mail Archives: djgpp-workers/2001/06/20/12:57:33
According to Eli Zaretskii:
> > while (s > 0) {
> > - if (--f->_cnt > -f->_bufsiz && *(const char *)ptr != '\n')
> > + if (--f->_cnt > -(long signed int)f->_bufsiz && *(const char *)ptr != 'n')
> > *f->_ptr++ = *(const char *)ptr++;
>
> Isn't it better to introduce a new `long signed int' variable, assign
> to it the value of f->_bufsiz, and then use that new variable instead
> of f->_bufsiz? Let the optimizer do the dirty work ;-)
Like this?:
Index: src/libc/ansi/stdio/fwrite.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fwrite.c,v
retrieving revision 1.6
diff -p -u -r1.6 fwrite.c
--- src/libc/ansi/stdio/fwrite.c 2001/06/09 10:57:08 1.6
+++ src/libc/ansi/stdio/fwrite.c 2001/06/20 16:50:25
@@ -12,7 +12,7 @@ size_t
fwrite(const void *vptr, size_t size, size_t count, FILE *f)
{
const char *ptr = (const char *)vptr;
- size_t s;
+ ssize_t s;
if (__libc_write_termios_hook
&& (f->_flag & (_IOTERM | _IONTERM)) == 0)
@@ -29,7 +29,9 @@ fwrite(const void *vptr, size_t size, si
{
if (f->_flag & _IOLBF)
while (s > 0) {
- if (--f->_cnt > -f->_bufsiz && *(const char *)ptr != '\n')
+ long signed int negative_bufsiz = -f->_bufsiz;
+
+ if (--f->_cnt > negative_bufsiz && *(const char *)ptr != '\n')
*f->_ptr++ = *(const char *)ptr++;
else if (_flsbuf(*(const char *)ptr++, f) == EOF)
break;
@@ -60,15 +62,17 @@ fwrite(const void *vptr, size_t size, si
if (f->_flag & _IOLBF)
{
while (s > 0) {
+ long signed int negative_bufsiz = -f->_bufsiz;
+
if (*ptr=='\n')
{
- if (--f->_cnt > -f->_bufsiz)
+ if (--f->_cnt > negative_bufsiz)
*f->_ptr++ = '\r';
else
if (_flsbuf('\r', f) == EOF)
break;
}
- if (--f->_cnt > -f->_bufsiz && *ptr != '\n')
+ if (--f->_cnt > negative_bufsiz && *ptr != '\n')
*f->_ptr++ = *ptr++;
else if (_flsbuf(*(const unsigned char *)ptr++, f) == EOF)
break;
- Raw text -