[vlc-commits] macosx: Fix filtering of log messages

Marvin Scholz git at videolan.org
Fri Sep 8 03:01:00 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Fri Sep  8 03:00:08 2017 +0200| [7576e56f0e4d120783fc126ef87f5375da20c563] | committer: Marvin Scholz

macosx: Fix filtering of log messages

Changes through the array controller are for the arrangedObjects, which
is the result of filtering and sorting.

Therefore we need to change the backing array. It is actually fine to do
that (contrary to my previous statement), as long as we behave correctly
and immediately send the appropriate KVO messages. Thats is why the
previous approach with just calling rearrangeObjects at some later point
after modifying the backing array would not work.

A big thanks to the AppKit Abusers Slack group, they provided a lot of
help to solve this.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7576e56f0e4d120783fc126ef87f5375da20c563
---

 modules/gui/macosx/VLCLogWindowController.m | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/modules/gui/macosx/VLCLogWindowController.m b/modules/gui/macosx/VLCLogWindowController.m
index 22d5c54162..34590d1e43 100644
--- a/modules/gui/macosx/VLCLogWindowController.m
+++ b/modules/gui/macosx/VLCLogWindowController.m
@@ -322,26 +322,31 @@ static void MsgCallback(void *data, int type, const vlc_log_t *item, const char
 }
 
 /**
- Clears all messages in the message table by removing all items from the arrayController
+ Clears all messages in the message table by removing all items from the messagesArray
  */
 - (void)clearMessageTable
 {
-    NSRange range = NSMakeRange(0, [[_arrayController arrangedObjects] count]);
-    [_arrayController removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:range]];
-}
+    [self willChangeValueForKey:@"messagesArray"];
+    [_messagesArray removeAllObjects];
+    [self didChangeValueForKey:@"messagesArray"];}
 
 /**
- Appends all messages from the buffer to the arrayController and clears the buffer
+ Appends all messages from the buffer to the messagesArray and clears the buffer
  */
 - (void)appendMessageBuffer
 {
-    if ([_messagesArray count] > 1000000) {
-        [_messagesArray removeObjectsInRange:NSMakeRange(0, 2)];
-    }
+    static const NSUInteger limit = 1000000;
+
+    [self willChangeValueForKey:@"messagesArray"];
     @synchronized (_messageBuffer) {
-        [_arrayController addObjects:_messageBuffer];
+        [_messagesArray addObjectsFromArray:_messageBuffer];
         [_messageBuffer removeAllObjects];
     }
+
+    if ([_messagesArray count] > limit) {
+        [_messagesArray removeObjectsInRange:NSMakeRange(0, _messagesArray.count - limit)];
+    }
+    [self didChangeValueForKey:@"messagesArray"];
 }
 
 @end



More information about the vlc-commits mailing list