diff --git a/MMBackend.h b/MMBackend.h index 353112c7c5..d0a577f3e8 100644 --- a/MMBackend.h +++ b/MMBackend.h @@ -26,6 +26,7 @@ int foregroundColor; int defaultBackgroundColor; int defaultForegroundColor; + NSDate *lastFlushDate; } + (MMBackend *)sharedInstance; @@ -45,8 +46,7 @@ flags:(int)flags; - (void)insertLinesFromRow:(int)row count:(int)count scrollBottom:(int)bottom left:(int)left right:(int)right; -- (void)flush; -- (void)flushQueue; +- (void)flushQueue:(BOOL)force; - (BOOL)waitForInput:(int)milliseconds; - (void)exit; - (void)selectTab:(int)index; diff --git a/MMBackend.m b/MMBackend.m index a2b14d64ee..7932b5748a 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -13,6 +13,9 @@ +static float MMFlushTimeoutInterval = 0.1f; + + // TODO: Move to separate file. static int eventModifierFlagsToVimModMask(int modifierFlags); static int vimModMaskToEventModifierFlags(int mods); @@ -243,24 +246,29 @@ static int specialKeyToNSKey(int key); [drawData appendBytes:&right length:sizeof(int)]; } -- (void)flush +- (void)flushQueue:(BOOL)force { + // NOTE! This method gets called a lot; if we were to flush every time it + // was called MacVim would feel unresponsive. So there is a time out which + // ensures that the queue isn't flushed too often. + if (!force && lastFlushDate && -[lastFlushDate timeIntervalSinceNow] + < MMFlushTimeoutInterval) + return; + if ([drawData length] > 0) { [self queueMessage:BatchDrawMsgID data:[drawData copy]]; [drawData setLength:0]; } -} -- (void)flushQueue -{ - [self flush]; - - if ([drawData length] > 0 || [queue count] > 0) { + if ([queue count] > 0) { // TODO: Come up with a better way to handle the insertion point. [self updateInsertionPoint]; [frontendProxy processCommandQueue:queue]; [queue removeAllObjects]; + + [lastFlushDate release]; + lastFlushDate = [[NSDate date] retain]; } } @@ -674,6 +682,9 @@ static int specialKeyToNSKey(int key); - (oneway void)processInput:(int)msgid data:(in NSData *)data { + [lastFlushDate release]; + lastFlushDate = [[NSDate date] retain]; + [self handleMessage:msgid data:data]; inputReceived = YES; } diff --git a/gui_macvim.m b/gui_macvim.m index 598755f6a2..dcf8253527 100644 --- a/gui_macvim.m +++ b/gui_macvim.m @@ -133,8 +133,7 @@ gui_mch_open(void) void gui_mch_update(void) { - // HACK! Nothing to do here since we tend to the run loop (which holds - // incoming events) in gui_mch_wait_for_chars(). + [[MMBackend sharedInstance] flushQueue:NO]; } @@ -142,13 +141,7 @@ gui_mch_update(void) void gui_mch_flush(void) { - // HACK! This function is called so often that draw performance suffers. - // Instead of actually flushing the output it is placed on a queue and - // flushed in gui_mch_wait_for_chars(), which makes the program feel much - // more responsive. This might have unintended side effects though; if - // so, another solution might have to be found. - - //[[MMBackend sharedInstance] flush]; + [[MMBackend sharedInstance] flushQueue:NO]; } @@ -164,8 +157,9 @@ gui_mch_flush(void) int gui_mch_wait_for_chars(int wtime) { - // HACK! See comment in gui_mch_flush(). - [[MMBackend sharedInstance] flushQueue]; + // NOTE! In all likelyhood Vim will take a nap when waitForInput: is + // called, so force a flush of the command queue here. + [[MMBackend sharedInstance] flushQueue:YES]; return [[MMBackend sharedInstance] waitForInput:wtime]; }