Commit f1e644f1 authored by Marvin Scholz's avatar Marvin Scholz Committed by David
Browse files

macosx: use ObjC fast enumeration where possible

It's more concise, easier to read and less error-prone.
parent 0cd7e54f
......@@ -30,9 +30,8 @@
return;
}
NSUInteger count = array.count;
for (NSUInteger x = 0; x < count; x++) {
[self addItem:array[x]];
for (NSMenuItem *item in array) {
[self addItem:item];
}
}
......
......@@ -46,10 +46,7 @@ static bool b_old_spaces_style = YES;
+ (NSScreen *)screenWithDisplayID: (CGDirectDisplayID)displayID
{
NSUInteger count = [[NSScreen screens] count];
for ( NSUInteger i = 0; i < count; i++ ) {
NSScreen *screen = [[NSScreen screens] objectAtIndex:i];
for (NSScreen *screen in [NSScreen screens]) {
if ([screen displayID] == displayID)
return screen;
}
......@@ -95,9 +92,7 @@ static bool b_old_spaces_style = YES;
[blackoutWindows makeObjectsPerformSelector:@selector(close)];
[blackoutWindows removeAllObjects];
NSUInteger screenCount = [[NSScreen screens] count];
for (NSUInteger i = 0; i < screenCount; i++) {
NSScreen *screen = [[NSScreen screens] objectAtIndex:i];
for (NSScreen *screen in [NSScreen screens]) {
VLCWindow *blackoutWindow;
NSRect screen_rect;
......@@ -128,10 +123,7 @@ static bool b_old_spaces_style = YES;
+ (void)unblackoutScreens
{
NSUInteger blackoutWindowCount = [blackoutWindows count];
for (NSUInteger i = 0; i < blackoutWindowCount; i++) {
VLCWindow *blackoutWindow = [blackoutWindows objectAtIndex:i];
for (VLCWindow *blackoutWindow in blackoutWindows) {
[[blackoutWindow screen] setNonFullscreenPresentationOptions];
[blackoutWindow closeAndAnimate: YES];
}
......
......@@ -334,9 +334,7 @@ NSString * getVolumeTypeFromMountPath(NSString *mountPath)
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:mountPath error:nil];
NSUInteger directoryContentCount = [directoryContents count];
for (NSUInteger i = 0; i < directoryContentCount; i++) {
NSString *currentFile = directoryContents[i];
for (NSString *currentFile in directoryContents) {
NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
BOOL isDirectory;
......
......@@ -108,11 +108,9 @@ const CGFloat LayoutSpacer;
_libraryController = [[VLCMain sharedInstance] libraryController];
}
NSArray *tracks = [_representedAlbum tracksAsMediaItems];
NSUInteger trackCount = tracks.count;
BOOL playImmediately = YES;
for (NSUInteger x = 0; x < trackCount; x++) {
[_libraryController appendItemToPlaylist:tracks[x] playImmediately:playImmediately];
for (VLCMediaLibraryMediaItem *mediaItem in [_representedAlbum tracksAsMediaItems]) {
[_libraryController appendItemToPlaylist:mediaItem playImmediately:playImmediately];
if (playImmediately) {
playImmediately = NO;
}
......
......@@ -299,7 +299,7 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
- (void)collectionSelectionDoubleClickAction:(id)sender
{
NSArray *listOfAlbums;
NSArray <VLCMediaLibraryAlbum *> *listOfAlbums;
switch (_currentParentType) {
case VLC_ML_PARENT_ARTIST:
......@@ -340,8 +340,8 @@ static NSString *VLCAudioLibraryCellIdentifier = @"VLCAudioLibraryCellIdentifier
}
VLCLibraryController *libraryController = [[VLCMain sharedInstance] libraryController];
for (NSUInteger x = 0; x < albumCount; x++) {
NSArray *tracks = [listOfAlbums[x] tracksAsMediaItems];
for (VLCMediaLibraryAlbum *album in listOfAlbums) {
NSArray *tracks = [album tracksAsMediaItems];
[libraryController appendItemsToPlaylist:tracks playFirstItemImmediately:YES];
}
}
......
......@@ -58,20 +58,14 @@
[textContent appendFormat:@"Small artwork generated? %@\n", _representedMediaItem.smallArtworkGenerated == YES ? _NS("Yes") : _NS("No")];
[textContent appendFormat:@"Favorited? %@, Playback progress: %2.f%%\n", _representedMediaItem.smallArtworkGenerated == YES ? _NS("Yes") : _NS("No"), _representedMediaItem.progress * 100.];
NSArray *array = _representedMediaItem.files;
NSUInteger count = array.count;
[textContent appendFormat:@"\nNumber of files: %lu\n", count];
for (NSUInteger x = 0; x < count; x++) {
VLCMediaLibraryFile *file = array[x];
[textContent appendFormat:@"\nNumber of files: %lu\n", _representedMediaItem.files.count];
for (VLCMediaLibraryFile *file in _representedMediaItem.files) {
[textContent appendFormat:@"URL: %@\n", file.fileURL];
[textContent appendFormat:@"Type: %@\n", file.readableFileType];
}
array = _representedMediaItem.tracks;
count = array.count;
[textContent appendFormat:@"\nNumber of tracks: %lu\n", count];
for (NSUInteger x = 0; x < count; x++) {
VLCMediaLibraryTrack *track = array[x];
[textContent appendFormat:@"\nNumber of tracks: %lu\n", _representedMediaItem.tracks.count];
for (VLCMediaLibraryTrack *track in _representedMediaItem.tracks) {
[textContent appendFormat:@"Type: %@\n", track.readableTrackType];
[textContent appendFormat:@"Codec: %@ (%@) @ %u kB/s\n", track.readableCodecName, track.codec, track.bitrate / 1024 / 8];
if (track.language.length > 0) {
......
......@@ -102,11 +102,8 @@
NSModalResponse modalResponse = [openPanel runModal];
if (modalResponse == NSModalResponseOK) {
NSArray *URLs = [openPanel URLs];
NSUInteger count = [URLs count];
VLCLibraryController *libraryController = [[VLCMain sharedInstance] libraryController];
for (NSUInteger i = 0; i < count ; i++) {
NSURL *url = URLs[i];
for (NSURL *url in [openPanel URLs]) {
[libraryController addFolderWithFileURL:url];
}
}
......@@ -120,11 +117,9 @@
- (void)moveToTrash:(id)sender
{
NSArray *filesToTrash = self.representedMediaItem.files;
NSUInteger trashCount = filesToTrash.count;
NSFileManager *fileManager = [NSFileManager defaultManager];
for (NSUInteger x = 0; x < trashCount; x++) {
VLCMediaLibraryFile *fileToTrash = filesToTrash[x];
for (VLCMediaLibraryFile *fileToTrash in filesToTrash) {
[fileManager trashItemAtURL:fileToTrash.fileURL resultingItemURL:nil error:nil];
}
}
......
......@@ -498,9 +498,8 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
if (valueCount > 0) {
NSMutableArray *metadataArray = [NSMutableArray arrayWithCapacity:valueCount];
for (NSUInteger i = 0; i < valueCount; i++) {
for (NSString *filepath in values) {
VLCOpenInputMetadata *inputMetadata;
NSString *filepath = values[i];
inputMetadata = [VLCOpenInputMetadata inputMetaWithPath:filepath];
if (!inputMetadata)
......
......@@ -400,9 +400,8 @@ static VLCMain *sharedInstance = nil;
NSArray *o_sorted_names = [resultItems sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
NSMutableArray *o_result = [NSMutableArray arrayWithCapacity: [o_sorted_names count]];
for (NSUInteger i = 0; i < [o_sorted_names count]; i++) {
for (NSString *filepath in o_sorted_names) {
VLCOpenInputMetadata *inputMetadata;
NSString *filepath = [o_sorted_names objectAtIndex:i];
inputMetadata = [VLCOpenInputMetadata inputMetaWithPath:filepath];
if (!inputMetadata)
......
......@@ -981,8 +981,7 @@ typedef NS_ENUM(NSInteger, VLCObjectType) {
[menuItem setEnabled:YES];
[menu addItem:menuItem];
for (NSUInteger x = 0; x < count; x++) {
VLCTrackMetaData *metaDataItem = metadataArray[x];
for (VLCTrackMetaData *metaDataItem in metadataArray) {
menuItem = [[NSMenuItem alloc] initWithTitle:metaDataItem.name
action:@selector(selectTrack:)
keyEquivalent:@""];
......@@ -1257,10 +1256,7 @@ typedef NS_ENUM(NSInteger, VLCObjectType) {
i_returnValue = [openPanel runModal];
if (i_returnValue == NSModalResponseOK) {
NSArray *URLs = [openPanel URLs];
NSUInteger count = [URLs count];
for (int i = 0; i < count ; i++) {
NSURL *url = URLs[i];
for (NSURL *url in [openPanel URLs]) {
[_playerController addAssociatedMediaToCurrentFromURL:url
ofCategory:SPU_ES
shallSelectTrack:YES
......
......@@ -143,9 +143,9 @@ static NSString *VLCPlaylistCellIdentifier = @"VLCPlaylistCellIdentifier";
NSUInteger mediaCount = [mediaPaths count];
if (mediaCount > 0) {
NSMutableArray *metadataArray = [NSMutableArray arrayWithCapacity:mediaCount];
for (NSUInteger i = 0; i < mediaCount; i++) {
for (NSString *mediaPath in mediaPaths) {
VLCOpenInputMetadata *inputMetadata;
NSURL *url = [NSURL fileURLWithPath:mediaPaths[i] isDirectory:NO];
NSURL *url = [NSURL fileURLWithPath:mediaPath isDirectory:NO];
if (!url) {
continue;
}
......@@ -173,10 +173,7 @@ static NSString *VLCPlaylistCellIdentifier = @"VLCPlaylistCellIdentifier";
@throw;
}
NSUInteger arrayCount = array.count;
for (NSUInteger x = 0; x < arrayCount; x++) {
VLCMediaLibraryMediaItem *mediaItem = array[x];
for (VLCMediaLibraryMediaItem *mediaItem in array) {
[_playlistController addInputItem:mediaItem.inputItem.vlcInputItem atPosition:row startPlayback:NO];
}
......
......@@ -447,10 +447,8 @@ NSString *const VLCOpenTextFieldWasClicked = @"VLCOpenTextFieldWasClicked";
- (void)addStreamOutputOptionsToArray:(NSMutableArray *)options
{
NSArray *soutMRL = [_output soutMRL];
NSUInteger count = [soutMRL count];
for (NSUInteger i = 0 ; i < count ; i++)
[options addObject: [NSString stringWithString: [soutMRL objectAtIndex:i]]];
for (NSString *item in [_output soutMRL])
[options addObject: [NSString stringWithString: item]];
}
- (void)addScreenRecordingOptionsToArray:(NSMutableArray *)options
......@@ -548,13 +546,12 @@ NSString *const VLCOpenTextFieldWasClicked = @"VLCOpenTextFieldWasClicked";
NSUInteger count = [URLs count];
NSMutableArray *values = [NSMutableArray arrayWithCapacity:count];
NSMutableArray *array = [NSMutableArray arrayWithCapacity:count];
for (NSUInteger i = 0; i < count; i++)
[values addObject: [[URLs objectAtIndex:i] path]];
for (NSURL *url in URLs)
[values addObject: [url path]];
[values sortUsingSelector:@selector(caseInsensitiveCompare:)];
for (NSUInteger i = 0; i < count; i++) {
for (NSString *filepath in values) {
VLCOpenInputMetadata *inputMetadata;
NSString *filepath = [values objectAtIndex:i];
inputMetadata = [VLCOpenInputMetadata inputMetaWithPath:filepath];
if (!inputMetadata)
continue;
......@@ -780,10 +777,8 @@ NSString *const VLCOpenTextFieldWasClicked = @"VLCOpenTextFieldWasClicked";
{
@autoreleasepool {
NSArray *mountURLs = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:@[NSURLVolumeIsRemovableKey] options:NSVolumeEnumerationSkipHiddenVolumes];
NSUInteger count = [mountURLs count];
NSMutableArray *o_result = [NSMutableArray array];
for (NSUInteger i = 0; i < count; i++) {
NSURL *currentURL = [mountURLs objectAtIndex:i];
for (NSURL *currentURL in mountURLs) {
NSNumber *isRemovable = nil;
if (![currentURL getResourceValue:&isRemovable forKey:NSURLVolumeIsRemovableKey error:nil] || !isRemovable) {
......@@ -836,8 +831,7 @@ NSString *const VLCOpenTextFieldWasClicked = @"VLCOpenTextFieldWasClicked";
NSUInteger count = [self->_allMediaDevices count];
if (count > 0) {
for (NSUInteger i = 0; i < count ; i++) {
VLCOpenBlockDeviceDescription *deviceDescription = [self->_allMediaDevices objectAtIndex:i];
for (VLCOpenBlockDeviceDescription *deviceDescription in self->_allMediaDevices) {
[self->_discSelectorPopup addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:deviceDescription.path]];
}
......
......@@ -273,10 +273,8 @@ static void addonChangedCallback( addons_manager_t *manager,
BOOL installedOnly = _localAddonsOnlyCheckbox.state == NSOnState;
int type = (int)[[_typeSwitcher selectedItem] tag];
NSUInteger count = _addons.count;
NSMutableArray *filteredItems = [[NSMutableArray alloc] initWithCapacity:count];
for (NSUInteger x = 0; x < count; x++) {
VLCAddonListItem *currentItem = [_addons objectAtIndex:x];
NSMutableArray *filteredItems = [[NSMutableArray alloc] initWithCapacity:_addons.count];
for (VLCAddonListItem *currentItem in _addons) {
if (type != -1) {
if ([currentItem type] == type) {
if (installedOnly) {
......
......@@ -340,8 +340,8 @@
else {
[finalStreamAddress appendFormat: @"\"%@:%@", [urlItems firstObject], [self.streamPortTextField stringValue]];
NSUInteger itemCount = [urlItems count];
for (NSUInteger x = 0; x < itemCount; x++)
[finalStreamAddress appendFormat: @"/%@", [urlItems objectAtIndex:x]];
for (NSString *item in urlItems)
[finalStreamAddress appendFormat: @"/%@", item];
[finalStreamAddress appendString: @"\""];
}
......
......@@ -535,12 +535,9 @@ NSString *VLCWindowShouldShowController = @"VLCWindowShouldShowController";
}
}
NSArray *subviews = [[self videoView] subviews];
NSUInteger count = [subviews count];
for (NSUInteger x = 0; x < count; x++) {
if ([[subviews objectAtIndex:x] respondsToSelector:@selector(reshape)])
[[subviews objectAtIndex:x] reshape];
for (__kindof NSView *view in [[self videoView] subviews]) {
if ([view respondsToSelector:@selector(reshape)])
[view reshape];
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment