Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
79ff6c37 by Alexandre Janniaux at 2024-06-01T07:07:56+00:00
VLCLibraryHomeViewController: refactor notifications

NSNotificationCenter was used repeatedly with repeated allocation to the
autorelease pool in order to setup the suffix addition for the
notification name.

This commit uses a for-loop releasing the local autorelease allocations
and create the notification names on-the-fly to avoid repetition.

- - - - -


1 changed file:

- modules/gui/macosx/library/home-library/VLCLibraryHomeViewController.m


Changes:

=====================================
modules/gui/macosx/library/home-library/VLCLibraryHomeViewController.m
=====================================
@@ -69,64 +69,33 @@
         [self setupHomeLibraryViews];
 
         NSNotificationCenter *notificationCenter = 
NSNotificationCenter.defaultCenter;
-        [notificationCenter addObserver:self
-                               selector:@selector(libraryModelUpdated:)
-                                   name:VLCLibraryModelVideoMediaListReset
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               selector:@selector(libraryModelUpdated:)
-                                   name:VLCLibraryModelVideoMediaItemDeleted
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               selector:@selector(libraryModelUpdated:)
-                                   name:VLCLibraryModelAudioMediaListReset
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               selector:@selector(libraryModelUpdated:)
-                                   name:VLCLibraryModelAudioMediaItemDeleted
-                                 object:nil];
-
-        NSString * const videoMediaResetLongLoadStartNotification = 
[VLCLibraryModelVideoMediaListReset 
stringByAppendingString:VLCLongNotificationNameStartSuffix];
-        NSString * const videoMediaResetLongLoadFinishNotification = 
[VLCLibraryModelVideoMediaListReset 
stringByAppendingString:VLCLongNotificationNameFinishSuffix];
-        NSString * const audioMediaResetLongLoadStartNotification = 
[VLCLibraryModelAudioMediaListReset 
stringByAppendingString:VLCLongNotificationNameStartSuffix];
-        NSString * const audioMediaResetLongLoadFinishNotification = 
[VLCLibraryModelAudioMediaListReset 
stringByAppendingString:VLCLongNotificationNameFinishSuffix];
-        NSString * const videoMediaDeletedLongLoadStartNotification = 
[VLCLibraryModelVideoMediaItemDeleted 
stringByAppendingString:VLCLongNotificationNameStartSuffix];
-        NSString * const videoMediaDeletedLongLoadFinishNotification = 
[VLCLibraryModelVideoMediaItemDeleted 
stringByAppendingString:VLCLongNotificationNameFinishSuffix];
-        NSString * const audioMediaDeletedLongLoadStartNotification = 
[VLCLibraryModelAudioMediaItemDeleted 
stringByAppendingString:VLCLongNotificationNameStartSuffix];
-        NSString * const audioMediaDeletedLongLoadFinishNotification = 
[VLCLibraryModelAudioMediaItemDeleted 
stringByAppendingString:VLCLongNotificationNameFinishSuffix];
-
-        [notificationCenter addObserver:self
-                               selector:@selector(libraryModelLongLoadStarted:)
-                                   
name:videoMediaResetLongLoadStartNotification
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               
selector:@selector(libraryModelLongLoadFinished:)
-                                   
name:videoMediaResetLongLoadFinishNotification
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               selector:@selector(libraryModelLongLoadStarted:)
-                                   
name:audioMediaResetLongLoadStartNotification
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               
selector:@selector(libraryModelLongLoadFinished:)
-                                   
name:audioMediaResetLongLoadFinishNotification
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               selector:@selector(libraryModelLongLoadStarted:)
-                                   
name:videoMediaDeletedLongLoadStartNotification
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               
selector:@selector(libraryModelLongLoadFinished:)
-                                   
name:videoMediaDeletedLongLoadFinishNotification
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               selector:@selector(libraryModelLongLoadStarted:)
-                                   
name:audioMediaDeletedLongLoadStartNotification
-                                 object:nil];
-        [notificationCenter addObserver:self
-                               
selector:@selector(libraryModelLongLoadFinished:)
-                                   
name:audioMediaDeletedLongLoadFinishNotification
-                                 object:nil];
+        NSString *notificationNames[] =
+        {
+            VLCLibraryModelVideoMediaListReset,
+            VLCLibraryModelAudioMediaListReset,
+            VLCLibraryModelVideoMediaItemDeleted,
+            VLCLibraryModelAudioMediaItemDeleted,
+        };
+
+        for (size_t i = 0; i < ARRAY_SIZE(notificationNames); ++i) 
@autoreleasepool
+        {
+            [notificationCenter addObserver:self
+                                   selector:@selector(libraryModelUpdated:)
+                                       name:notificationNames[i]
+                                     object:nil];
+
+            NSString *startedNotification = [notificationNames[i] 
stringByAppendingString:VLCLongNotificationNameStartSuffix];
+            [notificationCenter addObserver:self
+                                   
selector:@selector(libraryModelLongLoadStarted:)
+                                       name:startedNotification
+                                     object:nil];
+
+            NSString *finishedNotification = [notificationNames[i] 
stringByAppendingString:VLCLongNotificationNameFinishSuffix];
+            [notificationCenter addObserver:self
+                                   
selector:@selector(libraryModelLongLoadFinished:)
+                                       name:finishedNotification
+                                     object:nil];
+        }
     }
 
     return self;



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/79ff6c37870fef51f26705c695a1b051531f6db6

-- 
This project does not include diff previews in email notifications.
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/79ff6c37870fef51f26705c695a1b051531f6db6
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to