Revision: 4374
http://skim-app.svn.sourceforge.net/skim-app/?rev=4374&view=rev
Author: hofman
Date: 2008-08-11 17:03:11 +0000 (Mon, 11 Aug 2008)
Log Message:
-----------
Make use of gcc ?: operator.
Modified Paths:
--------------
trunk/NSAttributedString_SKExtensions.m
trunk/SKBookmarkController.m
trunk/SKColorSwatch.m
trunk/SKDownload.m
trunk/SKFontWell.m
trunk/SKLineWell.m
trunk/SKMainWindowController.m
trunk/SKPDFSynchronizer.m
trunk/SKSideWindow.m
trunk/SKTemplateParser.m
trunk/SKTransitionController.m
Modified: trunk/NSAttributedString_SKExtensions.m
===================================================================
--- trunk/NSAttributedString_SKExtensions.m 2008-08-11 13:07:24 UTC (rev
4373)
+++ trunk/NSAttributedString_SKExtensions.m 2008-08-11 17:03:11 UTC (rev
4374)
@@ -43,7 +43,7 @@
@implementation NSAttributedString (SKExtensions)
- (NSAttributedString *)accessibilityAttributedString {
- NSTextFieldCell *cell = nil;
+ static NSTextFieldCell *cell = nil;
if (cell == nil)
cell = [[NSTextFieldCell alloc] init];
[cell setAttributedStringValue:self];
Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKBookmarkController.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -539,8 +539,7 @@
#pragma mark NSOutlineView datasource methods
- (int)outlineView:(NSOutlineView *)ov numberOfChildrenOfItem:(id)item {
- if (item == nil) item = bookmarkRoot;
- return [item countOfChildren];
+ return [(item ?: bookmarkRoot) countOfChildren];
}
- (BOOL)outlineView:(NSOutlineView *)ov isItemExpandable:(id)item {
@@ -548,8 +547,7 @@
}
- (id)outlineView:(NSOutlineView *)ov child:(int)anIndex ofItem:(id)item {
- if (item == nil) item = bookmarkRoot;
- return [item objectInChildrenAtIndex:anIndex];
+ return [(item ?: bookmarkRoot) objectInChildrenAtIndex:anIndex];
}
- (id)outlineView:(NSOutlineView *)ov objectValueForTableColumn:(NSTableColumn
*)tableColumn byItem:(id)item {
Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKColorSwatch.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -426,10 +426,7 @@
}
- (NSDictionary *)infoForBinding:(NSString *)bindingName {
- NSDictionary *info = [bindingInfo objectForKey:bindingName];
- if (info == nil)
- info = [super infoForBinding:bindingName];
- return info;
+ return [bindingInfo objectForKey:bindingName] ?: [super
infoForBinding:bindingName];
}
#pragma mark NSDraggingSource protocol
Modified: trunk/SKDownload.m
===================================================================
--- trunk/SKDownload.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKDownload.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -136,10 +136,7 @@
}
- (NSString *)fileName {
- NSString *fileName = [[self filePath] lastPathComponent];
- if (fileName == nil)
- fileName = [[[self URL] path] lastPathComponent];
- return fileName;
+ return [([self filePath] ?: [[self URL] path]) lastPathComponent];
}
- (NSImage *)fileIcon {
Modified: trunk/SKFontWell.m
===================================================================
--- trunk/SKFontWell.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKFontWell.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -347,10 +347,7 @@
}
- (NSDictionary *)infoForBinding:(NSString *)bindingName {
- NSDictionary *info = [bindingInfo objectForKey:bindingName];
- if (info == nil)
- info = [super infoForBinding:bindingName];
- return info;
+ return [bindingInfo objectForKey:bindingName] ?: [super
infoForBinding:bindingName];
}
#pragma mark NSDraggingDestination protocol
@@ -390,9 +387,7 @@
NSArray *fontDescriptors = [dict
objectForKey:SKNSFontCollectionFontDescriptors];
NSFontDescriptor *fontDescriptor = ([fontDescriptors
isKindOfClass:[NSArray class]] && [fontDescriptors count]) ? [fontDescriptors
objectAtIndex:0] : nil;
if ([fontDescriptor isKindOfClass:[NSFontDescriptor class]]) {
- NSNumber *size = [[fontDescriptor fontAttributes]
objectForKey:NSFontSizeAttribute];
- if (size == nil)
- size = [dict objectForKey:NSFontSizeAttribute];
+ NSNumber *size = [[fontDescriptor fontAttributes]
objectForKey:NSFontSizeAttribute] ?: [dict objectForKey:NSFontSizeAttribute];
float fontSize = [size
respondsToSelector:@selector(floatValue)] ? [size floatValue] : [self fontSize];
droppedFont = [NSFont fontWithDescriptor:fontDescriptor
size:fontSize];
}
Modified: trunk/SKLineWell.m
===================================================================
--- trunk/SKLineWell.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKLineWell.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -735,10 +735,7 @@
}
- (NSDictionary *)infoForBinding:(NSString *)bindingName {
- NSDictionary *info = [bindingInfo objectForKey:bindingName];
- if (info == nil)
- info = [super infoForBinding:bindingName];
- return info;
+ return [bindingInfo objectForKey:bindingName] ?: [super
infoForBinding:bindingName];
}
#pragma mark NSDraggingSource protocol
@@ -801,7 +798,7 @@
- (NSArray *)accessibilityAttributeNames {
static NSArray *attributes = nil;
if (attributes == nil) {
- attributes = [[NSArray alloc] initWithObjects:
+ attributes = [[NSArray alloc] initWithObjects:
NSAccessibilityRoleAttribute,
NSAccessibilityRoleDescriptionAttribute,
NSAccessibilityValueAttribute,
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKMainWindowController.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -395,12 +395,8 @@
[pdfView setGreekingThreshold:[sud floatForKey:SKGreekingThresholdKey]];
[pdfView setBackgroundColor:[sud colorForKey:SKBackgroundColorKey]];
- NSNumber *leftWidth = [savedNormalSetup
objectForKey:SKMainWindowLeftSidePaneWidthKey];
- NSNumber *rightWidth = [savedNormalSetup
objectForKey:SKMainWindowRightSidePaneWidthKey];
- if (leftWidth == nil)
- leftWidth = [sud objectForKey:SKLeftSidePaneWidthKey];
- if (rightWidth == nil)
- rightWidth = [sud objectForKey:SKRightSidePaneWidthKey];
+ NSNumber *leftWidth = [savedNormalSetup
objectForKey:SKMainWindowLeftSidePaneWidthKey] ?: [sud
objectForKey:SKLeftSidePaneWidthKey];
+ NSNumber *rightWidth = [savedNormalSetup
objectForKey:SKMainWindowRightSidePaneWidthKey] ?: [sud
objectForKey:SKRightSidePaneWidthKey];
if (leftWidth && rightWidth) {
float width = [leftWidth floatValue];
@@ -625,9 +621,7 @@
accessoryView = colorAccessoryView;
}
if ([annotation respondsToSelector:@selector(setInteriorColor:)]
&& [colorAccessoryView state] == NSOnState) {
- color = [(id)annotation interiorColor];
- if (color == nil)
- color = [NSColor clearColor];
+ color = [(id)annotation interiorColor] ?: [NSColor clearColor];
} else {
color = [annotation color];
}
@@ -1270,9 +1264,7 @@
PDFAnnotation *annotation = [pdfView activeAnnotation];
if (updatingColor == NO && [annotation isSkimNote]) {
BOOL isFill = [colorAccessoryView state] == NSOnState && [annotation
respondsToSelector:@selector(setInteriorColor:)];
- NSColor *color = isFill ? [(id)annotation interiorColor] : [annotation
color];
- if (color == nil)
- color = [NSColor clearColor];
+ NSColor *color = (isFill ? [(id)annotation interiorColor] :
[annotation color]) ?: [NSColor clearColor];
if ([color isEqual:[sender color]] == NO) {
updatingColor = YES;
if (isFill)
@@ -1823,11 +1815,9 @@
- (IBAction)crop:(id)sender {
NSRect rect = NSIntegralRect([pdfView currentSelectionRect]);
- PDFPage *page = [pdfView currentSelectionPage];
+ PDFPage *page = [pdfView currentSelectionPage] ?: [pdfView currentPage];
if (NSIsEmptyRect(rect))
rect = [[pdfView currentSelectionPage] foregroundBox];
- if (page == nil)
- page = [pdfView currentPage];
[self cropPageAtIndex:[page pageIndex] toRect:rect];
}
@@ -2449,12 +2439,9 @@
}
- (void)goFullScreen {
- NSScreen *screen = [[self window] screen]; // @@ screen: or should we use
the main screen?
+ NSScreen *screen = [[self window] screen] ?: [NSScreen mainScreen]; // @@
screen: or should we use the main screen?
NSColor *backgroundColor = [self isPresentation] ? [NSColor blackColor] :
[[NSUserDefaults standardUserDefaults]
colorForKey:SKFullScreenBackgroundColorKey];
- if (screen == nil) // @@ screen: can this ever happen?
- screen = [NSScreen mainScreen];
-
// Create the full-screen window if it does not already exist.
if (fullScreenWindow == nil) {
fullScreenWindow = [[SKFullScreenWindow alloc] initWithScreen:screen];
@@ -2609,9 +2596,7 @@
if ([self isFullScreen])
return;
- NSScreen *screen = [[self window] screen]; // @@ screen: or should we use
the main screen?
- if (screen == nil) // @@ screen: can this ever happen?
- screen = [NSScreen mainScreen];
+ NSScreen *screen = [[self window] screen] ?: [NSScreen mainScreen]; // @@
screen: or should we use the main screen?
if ([screen isEqual:[[NSScreen screens] objectAtIndex:0]])
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
@@ -2638,9 +2623,7 @@
[self enterPresentationMode];
- NSScreen *screen = [[self window] screen]; // @@ screen: or should we use
the main screen?
- if (screen == nil) // @@ screen: can this ever happen?
- screen = [NSScreen mainScreen];
+ NSScreen *screen = [[self window] screen] ?: [NSScreen mainScreen]; // @@
screen: or should we use the main screen?
if ([screen isEqual:[[NSScreen screens] objectAtIndex:0]])
SetSystemUIMode(kUIModeAllHidden, 0);
@@ -2805,11 +2788,8 @@
- (void)addAnnotationsForSelection:(PDFSelection *)sel {
NSArray *pages = [sel pages];
int i, iMax = [pages count];
- NSColor *color = [[NSUserDefaults standardUserDefaults]
colorForKey:SKSearchHighlightColorKey];
+ NSColor *color = [[NSUserDefaults standardUserDefaults]
colorForKey:SKSearchHighlightColorKey] ?: [NSColor redColor];
- if (color == nil)
- color = [NSColor redColor];
-
for (i = 0; i < iMax; i++) {
PDFPage *page = [pages objectAtIndex:i];
NSRect bounds = NSInsetRect([sel boundsForPage:page], -4.0, -4.0);
@@ -3492,11 +3472,9 @@
// Ignore changes that aren't really changes.
// How much processor time does this memory optimization cost? We
don't know, because we haven't measured it. The use of
NSKeyValueObservingOptionNew in -startObservingNotes:, which makes
NSKeyValueChangeNewKey entries appear in change dictionaries, definitely costs
something when KVO notifications are sent (it costs virtually nothing at
observer registration time). Regardless, it's probably a good idea to do simple
memory optimizations like this as they're discovered and debug just enough to
confirm that they're saving the expected memory (and not introducing bugs).
Later on it will be easier to test for good responsiveness and sample to hunt
down processor time problems than it will be to figure out where all the darn
memory went when your app turns out to be notably RAM-hungry (and therefore
slowing down _other_ apps on your user's computers too, if the problem is bad
enough to cause paging).
// Is this a premature optimization? No. Leaving out this very simple
check, because we're worried about the processor time cost of using
NSKeyValueChangeNewKey, would be a premature optimization.
- id newValue = [change objectForKey:NSKeyValueChangeNewKey];
- id oldValue = [change objectForKey:NSKeyValueChangeOldKey];
// We should be adding undo for nil values also. I'm not sure if KVO
does this automatically. Note that -setValuesForKeysWithDictionary: converts
NSNull back to nil.
- if (newValue == nil) newValue = [NSNull null];
- if (oldValue == nil) oldValue = [NSNull null];
+ id newValue = [change objectForKey:NSKeyValueChangeNewKey] ?: [NSNull
null];
+ id oldValue = [change objectForKey:NSKeyValueChangeOldKey] ?: [NSNull
null];
// All values are suppsed to be true value objects that should be
compared with isEqual:
if ([newValue isEqual:oldValue] == NO) {
Modified: trunk/SKPDFSynchronizer.m
===================================================================
--- trunk/SKPDFSynchronizer.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKPDFSynchronizer.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -596,9 +596,7 @@
- (BOOL)synctexFindPage:(unsigned int *)pageIndex location:(NSPoint *)point
forLine:(int)line inFile:(NSString *)file {
BOOL rv = NO;
- NSString *filename = [filenames objectForKey:file];
- if (filename == nil)
- filename = [file lastPathComponent];
+ NSString *filename = [filenames objectForKey:file] ?: [file
lastPathComponent];
if (synctex_display_query(scanner, [filename fileSystemRepresentation],
line, 0) > 0) {
synctex_node_t node = synctex_next_result(scanner);
if (node) {
Modified: trunk/SKSideWindow.m
===================================================================
--- trunk/SKSideWindow.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKSideWindow.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -54,9 +54,7 @@
@implementation SKSideWindow
- (id)initWithMainController:(SKMainWindowController *)aController
edge:(NSRectEdge)anEdge {
- NSScreen *screen = [[aController window] screen];
- if (screen == nil)
- screen = [NSScreen mainScreen];
+ NSScreen *screen = [[aController window] screen] ?: [NSScreen mainScreen];
NSRect contentRect = [screen frame];
if (anEdge == NSMaxXEdge)
contentRect.origin.x = NSMaxX(contentRect) - DEFAULT_WINDOW_WIDTH;
Modified: trunk/SKTemplateParser.m
===================================================================
--- trunk/SKTemplateParser.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKTemplateParser.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -465,9 +465,7 @@
for (i = 0; i < count; i++) {
matchString = [matchStrings objectAtIndex:i];
if ([matchString hasPrefix:@"$"]) {
- matchString = [[object
templateValueForKeyPath:[matchString substringFromIndex:1]]
templateStringValue];
- if (matchString == nil)
- matchString = @"";
+ matchString = [[object
templateValueForKeyPath:[matchString substringFromIndex:1]]
templateStringValue] ?: @"";
}
switch ([tag matchType]) {
case SKTemplateTagMatchEqual:
@@ -784,9 +782,7 @@
for (i = 0; i < count; i++) {
matchString = [matchStrings objectAtIndex:i];
if ([matchString hasPrefix:@"$"]) {
- matchString = [[object
templateValueForKeyPath:[matchString substringFromIndex:1]]
templateStringValue];
- if (matchString == nil)
- matchString = @"";
+ matchString = [[object
templateValueForKeyPath:[matchString substringFromIndex:1]]
templateStringValue] ?: @"";
}
switch ([tag matchType]) {
case SKTemplateTagMatchEqual:
Modified: trunk/SKTransitionController.m
===================================================================
--- trunk/SKTransitionController.m 2008-08-11 13:07:24 UTC (rev 4373)
+++ trunk/SKTransitionController.m 2008-08-11 17:03:11 UTC (rev 4374)
@@ -604,9 +604,7 @@
if (context == nil) {
[[self openGLContext] makeCurrentContext];
- NSOpenGLPixelFormat *pf = [self pixelFormat];
- if (pf == nil)
- pf = [[self class] defaultPixelFormat];
+ NSOpenGLPixelFormat *pf = [self pixelFormat] ?: [[self class]
defaultPixelFormat];
context = [[CIContext contextWithCGLContext:CGLGetCurrentContext()
pixelFormat:[pf CGLPixelFormatObj] options:nil] retain];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit