diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-07-10 22:11:16 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-07-10 22:11:16 +0200 |
commit | 7c0a2f367f2507669560b1a66423155c70d2e75b (patch) | |
tree | 7cd0523311a25f653497197abc1fa86ed62bcc79 /src/channel.c | |
parent | ea3f2e7be447a8f0c4436869620f908de5e8ef1e (diff) |
patch 7.4.2024v7.4.2024
Problem: More buf_valid() calls can be optimized.
Solution: Use bufref_valid() instead.
Diffstat (limited to 'src/channel.c')
-rw-r--r-- | src/channel.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/channel.c b/src/channel.c index bb818dcd17..2e88080414 100644 --- a/src/channel.c +++ b/src/channel.c @@ -362,7 +362,7 @@ channel_still_useful(channel_T *channel) return TRUE; /* If reading from or a buffer it's still useful. */ - if (channel->ch_part[PART_IN].ch_buffer != NULL) + if (channel->ch_part[PART_IN].ch_bufref.br_buf != NULL) return TRUE; /* If there is no callback then nobody can get readahead. If the fd is @@ -379,9 +379,11 @@ channel_still_useful(channel_T *channel) return (channel->ch_callback != NULL && (has_sock_msg || has_out_msg || has_err_msg)) || ((channel->ch_part[PART_OUT].ch_callback != NULL - || channel->ch_part[PART_OUT].ch_buffer) && has_out_msg) + || channel->ch_part[PART_OUT].ch_bufref.br_buf != NULL) + && has_out_msg) || ((channel->ch_part[PART_ERR].ch_callback != NULL - || channel->ch_part[PART_ERR].ch_buffer) && has_err_msg); + || channel->ch_part[PART_ERR].ch_bufref.br_buf != NULL) + && has_err_msg); } /* @@ -1046,19 +1048,19 @@ channel_set_job(channel_T *channel, job_T *job, jobopt_T *options) { chanpart_T *in_part = &channel->ch_part[PART_IN]; - in_part->ch_buffer = job->jv_in_buf; + set_bufref(&in_part->ch_bufref, job->jv_in_buf); ch_logs(channel, "reading from buffer '%s'", - (char *)in_part->ch_buffer->b_ffname); + (char *)in_part->ch_bufref.br_buf->b_ffname); if (options->jo_set & JO_IN_TOP) { if (options->jo_in_top == 0 && !(options->jo_set & JO_IN_BOT)) { /* Special mode: send last-but-one line when appending a line * to the buffer. */ - in_part->ch_buffer->b_write_to_channel = TRUE; + in_part->ch_bufref.br_buf->b_write_to_channel = TRUE; in_part->ch_buf_append = TRUE; in_part->ch_buf_top = - in_part->ch_buffer->b_ml.ml_line_count + 1; + in_part->ch_bufref.br_buf->b_ml.ml_line_count + 1; } else in_part->ch_buf_top = options->jo_in_top; @@ -1068,7 +1070,7 @@ channel_set_job(channel_T *channel, job_T *job, jobopt_T *options) if (options->jo_set & JO_IN_BOT) in_part->ch_buf_bot = options->jo_in_bot; else - in_part->ch_buf_bot = in_part->ch_buffer->b_ml.ml_line_count; + in_part->ch_buf_bot = in_part->ch_bufref.br_buf->b_ml.ml_line_count; } } @@ -1229,7 +1231,7 @@ channel_set_options(channel_T *channel, jobopt_T *opt) { ch_logs(channel, "writing out to buffer '%s'", (char *)buf->b_ffname); - channel->ch_part[PART_OUT].ch_buffer = buf; + set_bufref(&channel->ch_part[PART_OUT].ch_bufref, buf); } } } @@ -1244,7 +1246,7 @@ channel_set_options(channel_T *channel, jobopt_T *opt) if (!(opt->jo_set & JO_ERR_MODE)) channel->ch_part[PART_ERR].ch_mode = MODE_NL; if (opt->jo_io[PART_ERR] == JIO_OUT) - buf = channel->ch_part[PART_OUT].ch_buffer; + buf = channel->ch_part[PART_OUT].ch_bufref.br_buf; else if (opt->jo_set & JO_ERR_BUF) { buf = buflist_findnr(opt->jo_io_buf[PART_ERR]); @@ -1266,7 +1268,7 @@ channel_set_options(channel_T *channel, jobopt_T *opt) { ch_logs(channel, "writing err to buffer '%s'", (char *)buf->b_ffname); - channel->ch_part[PART_ERR].ch_buffer = buf; + set_bufref(&channel->ch_part[PART_ERR].ch_bufref, buf); } } } @@ -1407,15 +1409,15 @@ channel_write_in(channel_T *channel) { chanpart_T *in_part = &channel->ch_part[PART_IN]; linenr_T lnum; - buf_T *buf = in_part->ch_buffer; + buf_T *buf = in_part->ch_bufref.br_buf; int written = 0; if (buf == NULL || in_part->ch_buf_append) return; /* no buffer or using appending */ - if (!buf_valid(buf) || buf->b_ml.ml_mfp == NULL) + if (!bufref_valid(&in_part->ch_bufref) || buf->b_ml.ml_mfp == NULL) { /* buffer was wiped out or unloaded */ - in_part->ch_buffer = NULL; + in_part->ch_bufref.br_buf = NULL; return; } @@ -1437,7 +1439,7 @@ channel_write_in(channel_T *channel) if (lnum > buf->b_ml.ml_line_count) { /* Writing is done, no longer need the buffer. */ - in_part->ch_buffer = NULL; + in_part->ch_bufref.br_buf = NULL; ch_log(channel, "Finished writing all lines to channel"); } else @@ -1459,11 +1461,11 @@ channel_buffer_free(buf_T *buf) { chanpart_T *ch_part = &channel->ch_part[part]; - if (ch_part->ch_buffer == buf) + if (ch_part->ch_bufref.br_buf == buf) { ch_logs(channel, "%s buffer has been wiped out", part_names[part]); - ch_part->ch_buffer = NULL; + ch_part->ch_bufref.br_buf = NULL; } } } @@ -1480,10 +1482,10 @@ channel_write_any_lines(void) { chanpart_T *in_part = &channel->ch_part[PART_IN]; - if (in_part->ch_buffer != NULL) + if (in_part->ch_bufref.br_buf != NULL) { if (in_part->ch_buf_append) - channel_write_new_lines(in_part->ch_buffer); + channel_write_new_lines(in_part->ch_bufref.br_buf); else channel_write_in(channel); } @@ -1507,7 +1509,7 @@ channel_write_new_lines(buf_T *buf) linenr_T lnum; int written = 0; - if (in_part->ch_buffer == buf && in_part->ch_buf_append) + if (in_part->ch_bufref.br_buf == buf && in_part->ch_buf_append) { if (in_part->ch_fd == INVALID_FD) continue; /* pipe was closed */ @@ -2312,7 +2314,7 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, int part) { chanpart_T *in_part = &ch->ch_part[PART_IN]; - if (in_part->ch_buffer == buffer) + if (in_part->ch_bufref.br_buf == buffer) in_part->ch_buf_bot = buffer->b_ml.ml_line_count; } } @@ -2374,11 +2376,11 @@ may_invoke_callback(channel_T *channel, int part) partial = channel->ch_partial; } - buffer = channel->ch_part[part].ch_buffer; - if (buffer != NULL && !buf_valid(buffer)) + buffer = channel->ch_part[part].ch_bufref.br_buf; + if (buffer != NULL && !bufref_valid(&channel->ch_part[part].ch_bufref)) { /* buffer was wiped out */ - channel->ch_part[part].ch_buffer = NULL; + channel->ch_part[part].ch_bufref.br_buf = NULL; buffer = NULL; } @@ -2834,7 +2836,7 @@ channel_fill_wfds(int maxfd_arg, fd_set *wfds) { chanpart_T *in_part = &ch->ch_part[PART_IN]; - if (in_part->ch_fd != INVALID_FD && in_part->ch_buffer != NULL) + if (in_part->ch_fd != INVALID_FD && in_part->ch_bufref.br_buf != NULL) { FD_SET((int)in_part->ch_fd, wfds); if ((int)in_part->ch_fd >= maxfd) @@ -2857,7 +2859,7 @@ channel_fill_poll_write(int nfd_in, struct pollfd *fds) { chanpart_T *in_part = &ch->ch_part[PART_IN]; - if (in_part->ch_fd != INVALID_FD && in_part->ch_buffer != NULL) + if (in_part->ch_fd != INVALID_FD && in_part->ch_bufref.br_buf != NULL) { in_part->ch_poll_idx = nfd; fds[nfd].fd = in_part->ch_fd; @@ -3643,8 +3645,8 @@ channel_poll_check(int ret_in, void *fds_in) { if (in_part->ch_buf_append) { - if (in_part->ch_buffer != NULL) - channel_write_new_lines(in_part->ch_buffer); + if (in_part->ch_bufref.br_buf != NULL) + channel_write_new_lines(in_part->ch_bufref.br_buf); } else channel_write_in(channel); @@ -3721,8 +3723,8 @@ channel_select_check(int ret_in, void *rfds_in, void *wfds_in) { if (in_part->ch_buf_append) { - if (in_part->ch_buffer != NULL) - channel_write_new_lines(in_part->ch_buffer); + if (in_part->ch_bufref.br_buf != NULL) + channel_write_new_lines(in_part->ch_bufref.br_buf); } else channel_write_in(channel); |