From 275dc33eb0ad879abfc2e330c25c3ba713643040 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Wed, 8 Apr 2009 20:38:28 +0200 Subject: [PATCH] Avoid enumerating vim controllers Don't enumerate vim controllers when processing input since it may potentially be a huge operation. If the vim controller array were to be modified during input processing (should never happen) MacVim would crash. --- src/MacVim/MMAppController.m | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 130a4162..70e59dc6 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -2148,13 +2148,19 @@ fsEventCallback(ConstFSEventStreamRef streamRef, NSDictionary *queues = inputQueues; inputQueues = [NSMutableDictionary new]; - MMVimController *vc; - NSEnumerator *e = [vimControllers objectEnumerator]; - while ((vc = [e nextObject])) { - NSNumber *key = [NSNumber numberWithUnsignedInt:[vc identifier]]; - NSArray *q = [queues objectForKey:key]; - if (q) - [vc processInputQueue:q]; + // Pass each input queue on to the vim controller with matching identifier. + NSEnumerator *e = [queues keyEnumerator]; + NSNumber *key; + while ((key = [e nextObject])) { + unsigned ukey = [key unsignedIntValue]; + int i = 0, count = [vimControllers count]; + for (i = 0; i < count; ++i) { + MMVimController *vc = [vimControllers objectAtIndex:i]; + if (ukey == [vc identifier]) { + [vc processInputQueue:[queues objectForKey:key]]; + break; + } + } } [queues release]; -- 2.11.4.GIT