Skip to content

Commit 12e1a00

Browse files
authored
Merge pull request #560 from ichizok/fix/slow-getchar
Fix the responsiveness of `getchar(0)`
2 parents 78e3217 + f113a44 commit 12e1a00

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/MacVim/gui_macvim.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@
333333
static CFAbsoluteTime lastTime = 0;
334334

335335
CFAbsoluteTime nowTime = CFAbsoluteTimeGetCurrent();
336-
if (nowTime - lastTime > 0.2) {
336+
if (nowTime - lastTime > 1.0 / 30) {
337337
[[MMBackend sharedInstance] update];
338338
lastTime = nowTime;
339339
}
@@ -2301,7 +2301,7 @@ static int vimModMaskToEventModifierFlags(int mods)
23012301
0,
23022302
dispatch_get_main_queue());
23032303
dispatch_source_set_event_handler(s, ^{
2304-
channel_read(channel, part, "gui_macvim_add_channel");
2304+
channel_may_read(channel, part, "gui_macvim_add_channel");
23052305
});
23062306
dispatch_resume(s);
23072307
return s;

src/channel.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@
5454
# define fd_close(sd) close(sd)
5555
#endif
5656

57-
#ifndef FEAT_GUI_MACVIM
5857
static void channel_read(channel_T *channel, ch_part_T part, char *func);
59-
#endif
6058

6159
/* Whether a redraw is needed for appending a line to a buffer. */
6260
static int channel_need_redraw = FALSE;
@@ -3271,11 +3269,7 @@ channel_close_now(channel_T *channel)
32713269
* "part" is PART_SOCK, PART_OUT or PART_ERR.
32723270
* The data is put in the read queue. No callbacks are invoked here.
32733271
*/
3274-
#ifndef FEAT_GUI_MACVIM
32753272
static void
3276-
#else
3277-
void
3278-
#endif
32793273
channel_read(channel_T *channel, ch_part_T part, char *func)
32803274
{
32813275
static char_u *buf = NULL;
@@ -3561,6 +3555,22 @@ common_channel_read(typval_T *argvars, typval_T *rettv, int raw)
35613555
free_job_options(&opt);
35623556
}
35633557

3558+
# ifdef FEAT_GUI_MACVIM
3559+
/*
3560+
* Read from channel "channel" in dispatch event handler.
3561+
* Channel may be already read out elsewhere before the handler invoked
3562+
* after an event arrived, so should be checked again.
3563+
*/
3564+
void
3565+
channel_may_read(channel_T *channel, ch_part_T part, char *func)
3566+
{
3567+
sock_T fd = channel->ch_part[part].ch_fd;
3568+
3569+
if (fd != INVALID_FD && channel_wait(channel, fd, 0) == CW_READY)
3570+
channel_read(channel, part, func);
3571+
}
3572+
# endif
3573+
35643574
# if defined(WIN32) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) \
35653575
|| defined(PROTO)
35663576
/*

src/proto/channel.pro

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void channel_clear(channel_T *channel);
3333
void channel_free_all(void);
3434
char_u *channel_read_block(channel_T *channel, ch_part_T part, int timeout);
3535
void common_channel_read(typval_T *argvars, typval_T *rettv, int raw);
36+
void channel_may_read(channel_T *channel, ch_part_T part, char *func);
3637
channel_T *channel_fd2channel(sock_T fd, ch_part_T *partp);
3738
void channel_handle_events(int only_keep_open);
3839
int channel_any_keep_open(void);
@@ -71,7 +72,4 @@ job_T *job_start(typval_T *argvars, jobopt_T *opt_arg);
7172
char *job_status(job_T *job);
7273
void job_info(job_T *job, dict_T *dict);
7374
int job_stop(job_T *job, typval_T *argvars, char *type);
74-
#ifdef FEAT_GUI_MACVIM
75-
void channel_read(channel_T *channel, ch_part_T part, char *func);
76-
#endif
7775
/* vim: set ft=c : */

0 commit comments

Comments
 (0)