To: vim_dev@googlegroups.com Subject: Patch 7.4.1668 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1668 Problem: channel_get_all() does multiple allocations. Solution: Compute the size and allocate once. Files: src/channel.c *** ../vim-7.4.1667/src/channel.c 2016-03-28 14:20:37.420765382 +0200 --- src/channel.c 2016-03-28 14:39:20.321263569 +0200 *************** *** 434,440 **** /* * Read a command from netbeans. - * TODO: instead of channel ID use the FD. */ #ifdef FEAT_GUI_X11 static void --- 434,439 ---- *************** *** 1325,1335 **** static char_u * channel_get_all(channel_T *channel, int part) { ! /* Concatenate everything into one buffer. ! * TODO: avoid multiple allocations. */ ! while (channel_collapse(channel, part) == OK) ! ; ! return channel_get(channel, part); } /* --- 1324,1357 ---- static char_u * channel_get_all(channel_T *channel, int part) { ! readq_T *head = &channel->ch_part[part].ch_head; ! readq_T *node = head->rq_next; ! long_u len = 1; ! char_u *res; ! char_u *p; ! ! /* If there is only one buffer just get that one. */ ! if (head->rq_next == NULL || head->rq_next->rq_next == NULL) ! return channel_get(channel, part); ! ! /* Concatenate everything into one buffer. */ ! for (node = head->rq_next; node != NULL; node = node->rq_next) ! len += (long_u)STRLEN(node->rq_buffer); ! res = lalloc(len, TRUE); ! if (res == NULL) ! return NULL; ! *res = NUL; ! for (node = head->rq_next; node != NULL; node = node->rq_next) ! STRCAT(res, node->rq_buffer); ! ! /* Free all buffers */ ! do ! { ! p = channel_get(channel, part); ! vim_free(p); ! } while (p != NULL); ! ! return res; } /* *************** *** 2504,2512 **** channel_save(channel, part, (char_u *)DETACH_MSG_RAW, (int)STRLEN(DETACH_MSG_RAW), FALSE, "PUT "); ! /* TODO: When reading from stdout is not possible, should we try to ! * keep stdin and stderr open? Probably not, assume the other side ! * has died. */ channel_close(channel, TRUE); if (channel->ch_nb_close_cb != NULL) (*channel->ch_nb_close_cb)(); --- 2526,2533 ---- channel_save(channel, part, (char_u *)DETACH_MSG_RAW, (int)STRLEN(DETACH_MSG_RAW), FALSE, "PUT "); ! /* When reading from stdout is not possible, assume the other side has ! * died. */ channel_close(channel, TRUE); if (channel->ch_nb_close_cb != NULL) (*channel->ch_nb_close_cb)(); *** ../vim-7.4.1667/src/version.c 2016-03-28 14:20:37.424765341 +0200 --- src/version.c 2016-03-28 14:40:19.568655049 +0200 *************** *** 750,751 **** --- 750,753 ---- { /* Add new patch number below this line */ + /**/ + 1668, /**/ -- Fingers not found - Pound head on keyboard to continue. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///