]> granicus.if.org Git - transmission/commitdiff
NSNumber literals
authorDmitry Serov <barbari100@gmail.com>
Fri, 7 Jul 2017 10:34:27 +0000 (17:34 +0700)
committerDmitry Serov <barbari100@gmail.com>
Fri, 7 Jul 2017 10:34:27 +0000 (17:34 +0700)
12 files changed:
macosx/Controller.m
macosx/FileOutlineController.m
macosx/FileOutlineView.m
macosx/FilePriorityCell.m
macosx/GroupsController.m
macosx/InfoTrackersViewController.m
macosx/MessageWindowController.m
macosx/NSStringAdditions.m
macosx/PortChecker.m
macosx/PrefsController.m
macosx/Torrent.m
macosx/TorrentTableView.m

index 7f924747f5d75c4fdf1fc0e0ebe49239d886ab9d..e47f409d696f6dd3abbcb71d0e30c3219dd1054e 100644 (file)
@@ -1199,7 +1199,7 @@ static void removeKeRangerRansomware()
 - (void) open: (NSArray *) files
 {
     NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: files, @"Filenames",
-                                [NSNumber numberWithInt: ADD_MANUAL], @"AddType", nil];
+                                @(ADD_MANUAL), @"AddType", nil];
     [self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dict waitUntilDone: NO];
 }
 
@@ -1221,7 +1221,7 @@ static void removeKeRangerRansomware()
                 [filenames addObject: [url path]];
 
             NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: filenames, @"Filenames",
-                                         [NSNumber numberWithInt: sender == fOpenIgnoreDownloadFolder ? ADD_SHOW_OPTIONS : ADD_MANUAL], @"AddType", nil];
+                sender == fOpenIgnoreDownloadFolder ? @(ADD_SHOW_OPTIONS) : @(ADD_MANUAL), @"AddType", nil];
             [self performSelectorOnMainThread: @selector(openFilesWithDict:) withObject: dictionary waitUntilDone: NO];
         }
     }];
@@ -2581,7 +2581,7 @@ static void removeKeRangerRansomware()
 
         NSMutableDictionary * groupsByIndex = [NSMutableDictionary dictionaryWithCapacity: [fDisplayedTorrents count]];
         for (TorrentGroup * group in fDisplayedTorrents)
-            [groupsByIndex setObject: group forKey: [NSNumber numberWithInteger: [group groupIndex]]];
+            [groupsByIndex setObject: group forKey: @([group groupIndex])];
 
         const NSUInteger originalGroupCount = [fDisplayedTorrents count];
         for (NSUInteger index = 0; index < originalGroupCount; ++index)
@@ -2606,11 +2606,11 @@ static void removeKeRangerRansomware()
                     const NSInteger groupValue = [torrent groupValue];
                     if (groupValue != [group groupIndex])
                     {
-                        TorrentGroup * newGroup = [groupsByIndex objectForKey: [NSNumber numberWithInteger: groupValue]];
+                        TorrentGroup * newGroup = [groupsByIndex objectForKey: @(groupValue)];
                         if (!newGroup)
                         {
                             newGroup = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
-                            [groupsByIndex setObject: newGroup forKey: [NSNumber numberWithInteger: groupValue]];
+                            [groupsByIndex setObject: newGroup forKey: @(groupValue)];
                             [fDisplayedTorrents addObject: newGroup];
 
                             [fTableView insertItemsAtIndexes: [NSIndexSet indexSetWithIndex: [fDisplayedTorrents count]-1] inParent: nil withAnimation: NSTableViewAnimationEffectFade];
@@ -2647,11 +2647,11 @@ static void removeKeRangerRansomware()
         for (Torrent * torrent in [allTorrents objectsAtIndexes: unusedAllTorrentsIndexes])
         {
             const NSInteger groupValue = [torrent groupValue];
-            TorrentGroup * group = [groupsByIndex objectForKey: [NSNumber numberWithInteger: groupValue]];
+            TorrentGroup * group = [groupsByIndex objectForKey: @(groupValue)];
             if (!group)
             {
                 group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
-                [groupsByIndex setObject: group forKey: [NSNumber numberWithInteger: groupValue]];
+                [groupsByIndex setObject: group forKey: @(groupValue)];
                 [fDisplayedTorrents addObject: group];
 
                 [fTableView insertItemsAtIndexes: [NSIndexSet indexSetWithIndex: [fDisplayedTorrents count]-1] inParent: nil withAnimation: NSTableViewAnimationEffectFade];
@@ -2702,11 +2702,11 @@ static void removeKeRangerRansomware()
             for (Torrent * torrent in allTorrents)
             {
                 const NSInteger groupValue = [torrent groupValue];
-                TorrentGroup * group = [groupsByIndex objectForKey: [NSNumber numberWithInteger: groupValue]];
+                TorrentGroup * group = [groupsByIndex objectForKey: @(groupValue)];
                 if (!group)
                 {
                     group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
-                    [groupsByIndex setObject: group forKey: [NSNumber numberWithInteger: groupValue]];
+                    [groupsByIndex setObject: group forKey: @(groupValue)];
                 }
 
                 [[group torrents] addObject: torrent];
index a0b8c3700e3cf67b1070206155f73cc8c3edad05..5318eb41ceb5c55c6c27dd46de6020d1cac767c6 100644 (file)
@@ -239,7 +239,7 @@ typedef enum
 - (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
 {
     if ([[tableColumn identifier] isEqualToString: @"Check"])
-        return [NSNumber numberWithInteger: [fTorrent checkForFiles: [(FileListNode *)item indexes]]];
+        return @([fTorrent checkForFiles: [(FileListNode *)item indexes]]);
     else
         return item;
 }
index e7fd03373799b22a5558195c16e7ad1583e66cf6..b6dc3197cec4dfaab36e8dce0c7065e2aca4de36 100644 (file)
     {
         FilePriorityCell * cell = (FilePriorityCell *)[self preparedCellAtColumn: col row: row];
 
-        NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
+        NSDictionary * userInfo = [NSDictionary dictionaryWithObject: @(row) forKey: @"Row"];
         [cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: col row: row] withUserInfo: userInfo
                 mouseLocation: mouseLocation];
     }
index b1a9f7c95e3ff79b26ada9f74c18a2ee7ebeaee3..ecc490cb7961011011ecec83a05387a1e9bd188a 100644 (file)
     const NSUInteger count = [priorities count];
     if (fHoverRow && count > 0)
     {
-        [super setSelected: [priorities containsObject: [NSNumber numberWithInteger: TR_PRI_LOW]] forSegment: 0];
-        [super setSelected: [priorities containsObject: [NSNumber numberWithInteger: TR_PRI_NORMAL]] forSegment: 1];
-        [super setSelected: [priorities containsObject: [NSNumber numberWithInteger: TR_PRI_HIGH]] forSegment: 2];
+        [super setSelected: [priorities containsObject: @(TR_PRI_LOW)] forSegment: 0];
+        [super setSelected: [priorities containsObject: @(TR_PRI_NORMAL)] forSegment: 1];
+        [super setSelected: [priorities containsObject: @(TR_PRI_HIGH)] forSegment: 2];
 
         [super drawWithFrame: cellFrame inView: controlView];
     }
             NSColor * priorityColor = [self backgroundStyle] == NSBackgroundStyleDark ? [NSColor whiteColor] : [NSColor darkGrayColor];
 
             totalWidth = 0.0;
-            if ([priorities containsObject: [NSNumber numberWithInteger: TR_PRI_LOW]])
+            if ([priorities containsObject: @(TR_PRI_LOW)])
             {
                 NSImage * image = [[NSImage imageNamed: @"PriorityLowTemplate"] imageWithColor: priorityColor];
                 [images addObject: image];
                 totalWidth += [image size].width;
             }
-            if ([priorities containsObject: [NSNumber numberWithInteger: TR_PRI_NORMAL]])
+            if ([priorities containsObject: @(TR_PRI_NORMAL)])
             {
                 NSImage * image = [[NSImage imageNamed: @"PriorityNormalTemplate"] imageWithColor: priorityColor];
                 [images addObject: image];
                 totalWidth += [image size].width;
             }
-            if ([priorities containsObject: [NSNumber numberWithInteger: TR_PRI_HIGH]])
+            if ([priorities containsObject: @(TR_PRI_HIGH)])
             {
                 NSImage * image = [[NSImage imageNamed: @"PriorityHighTemplate"] imageWithColor: priorityColor];
                 [images addObject: image];
index ca0136c4f12a48fa3cd7fcad9cf0f64e7a5d11f5..a36506ab207c982173a9f66199bd64a15f31838f 100644 (file)
@@ -65,37 +65,37 @@ GroupsController * fGroupsInstance = nil;
             NSMutableDictionary * red = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             [NSColor redColor], @"Color",
                                             NSLocalizedString(@"Red", "Groups -> Name"), @"Name",
-                                            [NSNumber numberWithInteger: 0], @"Index", nil];
+                                            @0, @"Index", nil];
 
             NSMutableDictionary * orange = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             [NSColor orangeColor], @"Color",
                                             NSLocalizedString(@"Orange", "Groups -> Name"), @"Name",
-                                            [NSNumber numberWithInteger: 1], @"Index", nil];
+                                            @1, @"Index", nil];
 
             NSMutableDictionary * yellow = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             [NSColor yellowColor], @"Color",
                                             NSLocalizedString(@"Yellow", "Groups -> Name"), @"Name",
-                                            [NSNumber numberWithInteger: 2], @"Index", nil];
+                                            @2, @"Index", nil];
 
             NSMutableDictionary * green = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             [NSColor greenColor], @"Color",
                                             NSLocalizedString(@"Green", "Groups -> Name"), @"Name",
-                                            [NSNumber numberWithInteger: 3], @"Index", nil];
+                                            @3, @"Index", nil];
 
             NSMutableDictionary * blue = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             [NSColor blueColor], @"Color",
                                             NSLocalizedString(@"Blue", "Groups -> Name"), @"Name",
-                                            [NSNumber numberWithInteger: 4], @"Index", nil];
+                                            @4, @"Index", nil];
 
             NSMutableDictionary * purple = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             [NSColor purpleColor], @"Color",
                                             NSLocalizedString(@"Purple", "Groups -> Name"), @"Name",
-                                            [NSNumber numberWithInteger: 5], @"Index", nil];
+                                            @5, @"Index", nil];
 
             NSMutableDictionary * gray = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                             [NSColor grayColor], @"Color",
                                             NSLocalizedString(@"Gray", "Groups -> Name"), @"Name",
-                                            [NSNumber numberWithInteger: 6], @"Index", nil];
+                                            @6, @"Index", nil];
 
             fGroups = [[NSMutableArray alloc] initWithObjects: red, orange, yellow, green, blue, purple, gray, nil];
             [self saveGroups]; //make sure this is saved right away
@@ -184,7 +184,7 @@ GroupsController * fGroupsInstance = nil;
 {
     NSMutableDictionary * dict = [fGroups objectAtIndex: [self rowValueForIndex: index]];
 
-    [dict setObject: [NSNumber numberWithBool: useCustomLocation] forKey: @"UsesCustomDownloadLocation"];
+    [dict setObject: @(useCustomLocation) forKey: @"UsesCustomDownloadLocation"];
 
     [[GroupsController groups] saveGroups];
 }
@@ -217,7 +217,7 @@ GroupsController * fGroupsInstance = nil;
 {
     NSMutableDictionary * dict = [fGroups objectAtIndex: [self rowValueForIndex: index]];
 
-    [dict setObject: [NSNumber numberWithBool: useAutoAssignRules] forKey: @"UsesAutoGroupRules"];
+    [dict setObject: @(useAutoAssignRules) forKey: @"UsesAutoGroupRules"];
 
     [[GroupsController groups] saveGroups];
 }
@@ -256,7 +256,7 @@ GroupsController * fGroupsInstance = nil;
 
     const NSInteger index = [candidates firstIndex];
 
-    [fGroups addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger: index], @"Index",
+    [fGroups addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys: @(index), @"Index",
                             [NSColor colorWithCalibratedRed: 0.0 green: 0.65 blue: 1.0 alpha: 1.0], @"Color", @"", @"Name", nil]];
 
     [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateGroups" object: self];
@@ -269,7 +269,7 @@ GroupsController * fGroupsInstance = nil;
     [fGroups removeObjectAtIndex: row];
 
     [[NSNotificationCenter defaultCenter] postNotificationName: @"GroupValueRemoved" object: self userInfo:
-        [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger: index] forKey: @"Index"]];
+        [NSDictionary dictionaryWithObject: @(index) forKey: @"Index"]];
 
     if (index == [[NSUserDefaults standardUserDefaults] integerForKey: @"FilterGroup"])
         [[NSUserDefaults standardUserDefaults] setInteger: -2 forKey: @"FilterGroup"];
index 78d8438d282cc9e6f620271ddbb696313503ba3e..0edabb04f23a3828b8cfe3e2032077b126af8fd9 100644 (file)
 
     NSAssert1([fTorrents count] == 1, @"Attempting to add tracker with %ld transfers selected", [fTorrents count]);
 
-    [fTrackers addObject: [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger: -1] forKey: @"Tier"]];
+    [fTrackers addObject: [NSDictionary dictionaryWithObject: @-1 forKey: @"Tier"]];
     [fTrackers addObject: @""];
 
     [fTrackerTable setTrackers: fTrackers];
index da0ff829610f144310a67e56c6c0329cb5c74768..4730a7985eaaac66acd3b6f999760d8fc19af1bf 100644 (file)
         NSDictionary * message  = [NSDictionary dictionaryWithObjectsAndKeys:
                                     [NSString stringWithUTF8String: currentMessage->message], @"Message",
                                     [NSDate dateWithTimeIntervalSince1970: currentMessage->when], @"Date",
-                                    [NSNumber numberWithUnsignedInteger: currentIndex++], @"Index", //more accurate when sorting by date
-                                    [NSNumber numberWithInteger: currentMessage->level], @"Level",
+                                    @(currentIndex++), @"Index", //more accurate when sorting by date
+                                    @(currentMessage->level), @"Level",
                                     name, @"Name",
                                     file, @"File", nil];
 
index 9f32230c0bdad73673c9acb8e0d87b97a1a47a09..40c1c35acf2dc45eab00cb3ea240d0277f089c40 100644 (file)
     [numberFormatter setMinimumFractionDigits: 0];
     [numberFormatter setMaximumFractionDigits: decimals];
 
-    NSString * fileSizeString = [numberFormatter stringFromNumber: [NSNumber numberWithFloat: convertedSize]];
+    NSString * fileSizeString = [numberFormatter stringFromNumber: @(convertedSize)];
     [numberFormatter release];
 
     if (!notAllowedUnit || ![unit isEqualToString: notAllowedUnit])
index 93f4dccf0507b23b1a4fca9c8b1327b5eb2d4690..0de2ac8cc7e52695cdab3d9a8bd2b35c8f44ffdd 100644 (file)
@@ -43,7 +43,7 @@
 
         fStatus = PORT_STATUS_CHECKING;
 
-        fTimer = [[NSTimer scheduledTimerWithTimeInterval: CHECK_FIRE target: self selector: @selector(startProbe:) userInfo: [NSNumber numberWithInteger: portNumber] repeats: NO] retain];
+        fTimer = [[NSTimer scheduledTimerWithTimeInterval: CHECK_FIRE target: self selector: @selector(startProbe:) userInfo: @(portNumber) repeats: NO] retain];
         if (!delay)
             [fTimer fire];
     }
index c64cd137f59c9066567db539d7456c667da6c340..e5675017ca962b42f3078ba1ac0dcd78abcceabd 100644 (file)
             {
                 int num = [component intValue];
                 if (num >= 0 && num < 256)
-                    [newComponents addObject: [[NSNumber numberWithInt: num] stringValue]];
+                    [newComponents addObject: [@(num) stringValue]];
                 else
                 {
                     valid = false;
index 740c1eb50312f82d27e2b95aa3c98a9fae2ca322..8d45b4dbb0fe2fda2c52fdfdf7b52c611c4c03bb 100644 (file)
@@ -227,10 +227,10 @@ bool trashDataFile(const char * filename, tr_error ** error)
     return [NSDictionary dictionaryWithObjectsAndKeys:
             [self torrentLocation], @"InternalTorrentPath",
             [self hashString], @"TorrentHash",
-            [NSNumber numberWithBool: [self isActive]], @"Active",
-            [NSNumber numberWithBool: [self waitingToStart]], @"WaitToStart",
-            [NSNumber numberWithInt: fGroupValue], @"GroupValue",
-            [NSNumber numberWithBool: fRemoveWhenFinishSeeding], @"RemoveWhenFinishSeeding", nil];
+            @([self isActive]), @"Active",
+            @([self waitingToStart]), @"WaitToStart",
+            @(fGroupValue), @"GroupValue",
+            @(fRemoveWhenFinishSeeding), @"RemoveWhenFinishSeeding", nil];
 }
 
 - (void) dealloc
@@ -969,20 +969,20 @@ bool trashDataFile(const char * filename, tr_error ** error)
         NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 12];
 
         [dict setObject: [self name] forKey: @"Name"];
-        [dict setObject: [NSNumber numberWithInt: peer->from] forKey: @"From"];
+        [dict setObject: @(peer->from) forKey: @"From"];
         [dict setObject: [NSString stringWithUTF8String: peer->addr] forKey: @"IP"];
-        [dict setObject: [NSNumber numberWithInt: peer->port] forKey: @"Port"];
-        [dict setObject: [NSNumber numberWithFloat: peer->progress] forKey: @"Progress"];
-        [dict setObject: [NSNumber numberWithBool: peer->isSeed] forKey: @"Seed"];
-        [dict setObject: [NSNumber numberWithBool: peer->isEncrypted] forKey: @"Encryption"];
-        [dict setObject: [NSNumber numberWithBool: peer->isUTP] forKey: @"uTP"];
+        [dict setObject: @(peer->port) forKey: @"Port"];
+        [dict setObject: @(peer->progress) forKey: @"Progress"];
+        [dict setObject: @(peer->isSeed) forKey: @"Seed"];
+        [dict setObject: @(peer->isEncrypted) forKey: @"Encryption"];
+        [dict setObject: @(peer->isUTP) forKey: @"uTP"];
         [dict setObject: [NSString stringWithUTF8String: peer->client] forKey: @"Client"];
         [dict setObject: [NSString stringWithUTF8String: peer->flagStr] forKey: @"Flags"];
 
         if (peer->isUploadingTo)
-            [dict setObject: [NSNumber numberWithDouble: peer->rateToPeer_KBps] forKey: @"UL To Rate"];
+            [dict setObject: @(peer->rateToPeer_KBps) forKey: @"UL To Rate"];
         if (peer->isDownloadingFrom)
-            [dict setObject: [NSNumber numberWithDouble: peer->rateToClient_KBps] forKey: @"DL From Rate"];
+            [dict setObject: @(peer->rateToClient_KBps) forKey: @"DL From Rate"];
 
         [peerDicts addObject: dict];
     }
@@ -1011,7 +1011,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
         [dict setObject: [NSString stringWithUTF8String: fInfo->webseeds[i]] forKey: @"Address"];
 
         if (dlSpeeds[i] != -1.0)
-            [dict setObject: [NSNumber numberWithDouble: dlSpeeds[i]] forKey: @"DL From Rate"];
+            [dict setObject: @(dlSpeeds[i]) forKey: @"DL From Rate"];
 
         [webSeeds addObject: dict];
     }
@@ -1552,7 +1552,7 @@ bool trashDataFile(const char * filename, tr_error ** error)
                 NSAssert2(NO, @"Unknown priority %d for file index %ld", priority, index);
         }
 
-        [priorities addObject: [NSNumber numberWithInteger: priority]];
+        [priorities addObject: @(priority)];
         if (low && normal && high)
             break;
     }
index e2c39aacf97676d28b6f0f07cd08c1b5b846c387..ee8dc2fbaf1a66d83abe1665643f69faa6db3768 100644 (file)
         if (![[self itemAtRow: row] isKindOfClass: [Torrent class]])
             continue;
 
-        NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger: row] forKey: @"Row"];
+        NSDictionary * userInfo = [NSDictionary dictionaryWithObject: @(row) forKey: @"Row"];
         TorrentCell * cell = (TorrentCell *)[self preparedCellAtColumn: -1 row: row];
         [cell addTrackingAreasForView: self inRect: [self rectOfRow: row] withUserInfo: userInfo mouseLocation: mouseLocation];
     }
                         "Action menu -> upload/download limit"), speedLimitActionValue[i]] action: @selector(setQuickLimit:)
                         keyEquivalent: @""];
                 [item setTarget: self];
-                [item setRepresentedObject: [NSNumber numberWithInt: speedLimitActionValue[i]]];
+                [item setRepresentedObject: @(speedLimitActionValue[i])];
                 [menu addItem: item];
                 [item release];
             }
                 item = [[NSMenuItem alloc] initWithTitle: [NSString localizedStringWithFormat: @"%.2f", ratioLimitActionValue[i]]
                         action: @selector(setQuickRatio:) keyEquivalent: @""];
                 [item setTarget: self];
-                [item setRepresentedObject: [NSNumber numberWithFloat: ratioLimitActionValue[i]]];
+                [item setRepresentedObject: @(ratioLimitActionValue[i])];
                 [menu addItem: item];
                 [item release];
             }
 {
     NSMutableArray * progressMarks = [NSMutableArray arrayWithCapacity: 16];
     for (NSAnimationProgress i = 0.0625; i <= 1.0; i += 0.0625)
-        [progressMarks addObject: [NSNumber numberWithFloat: i]];
+        [progressMarks addObject: @(i)];
 
     //this stops a previous animation
     [fPiecesBarAnimation release];