pike.git / src / modules / _Stdio / file.c

version» Context lines:

pike.git/src/modules/_Stdio/file.c:741:      static struct pike_string *do_read(int fd,    INT32 r,    int all,    INT_TYPE *err)   {    size_t bytes = r;    struct byte_buffer buf = BUFFER_INIT();    int e = 0;    +  buffer_set_flags(&buf, BUFFER_GROW_EXACT); +     THREADS_ALLOW();       while (bytes) {    size_t len = MINIMUM(DIRECT_BUFSIZE, bytes);    ptrdiff_t i;       /* make space for exactly len bytes plus the terminating null byte */ -  if (UNLIKELY(!buffer_make_space_nothrow(&buf, len+1))) { +  if (UNLIKELY(!buffer_ensure_space_nothrow(&buf, len+1))) {    buffer_free(&buf);    e = ENOMEM;    break;    }       i = fd_read(fd, buffer_alloc_unsafe(&buf, len), len);       if (LIKELY(i >= 0)) {    if ((size_t)i < len) buffer_remove(&buf, len - i);    bytes -= i;
pike.git/src/modules/_Stdio/file.c:989:    message.msg.msg_flags = 0;   #endif       {    /* For some reason, 8k seems to work faster than 64k.    * (4k seems to be about 2% faster than 8k when using linux though)    * /Hubbe (Per pointed it out to me..)    */    struct byte_buffer b = BUFFER_INIT();    +  buffer_set_flags(&b, BUFFER_GROW_EXACT); +     /* for small reads we allocate the whole size in the beginning,    * instead of only by individual chunks. We may want to change    * what small means.    */ -  if (r < 65*1024) buffer_make_space(&b, r+1); +  if (r < 65*1024) buffer_ensure_space(&b, r+1);       SET_ONERROR(ebuf, buffer_free, &b);    do{    int e;    const INT32 CHUNK = 1024 * 8;    INT32 try_read=MINIMUM(CHUNK,r);       /* allocate try_read bytes + the trailing null byte */ -  buffer_make_space(&b, try_read+1); +  buffer_ensure_space(&b, try_read+1);      #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL    message.msg.msg_control = &message.cmsgbuf;    message.msg.msg_controllen = sizeof(message.cmsgbuf);   #else    message.msg.msg_accrights = (void *)&message.cmsgbuf;    message.msg.msg_accrightslen = sizeof(message.cmsgbuf);   #endif    message.iov.iov_base = buffer_alloc(&b, try_read);    message.iov.iov_len = try_read;