adium 2419:5bd931f5aa4e: Avoid doing extra work when unnecessary.
commits at adium.im
commits at adium.im
Sun May 31 06:14:15 UTC 2009
details: http://hg.adium.im/adium/rev/5bd931f5aa4e
revision: 2419:5bd931f5aa4e
author: Zachary West <zacw at adium.im>
date: Sun May 31 02:14:06 2009 -0400
Avoid doing extra work when unnecessary.
diffs (25 lines):
diff -r 95a9b1378a82 -r 5bd931f5aa4e Plugins/Image Uploading Plugin/AIPicImImageUploader.m
--- a/Plugins/Image Uploading Plugin/AIPicImImageUploader.m Sat May 30 23:20:45 2009 -0400
+++ b/Plugins/Image Uploading Plugin/AIPicImImageUploader.m Sun May 31 02:14:06 2009 -0400
@@ -93,14 +93,19 @@
NSData *pngRepresentation = [[image largestBitmapImageRep] representationUsingType:NSPNGFileType properties:nil];
NSData *jpgRepresentation = [[image largestBitmapImageRep] representationUsingType:NSJPEGFileType properties:nil];
-
+ NSData *imageRepresentation;
+
if (pngRepresentation.length > jpgRepresentation.length) {
bestType = NSJPEGFileType;
+ imageRepresentation = jpgRepresentation;
} else {
bestType = NSPNGFileType;
+ imageRepresentation = pngRepresentation;
}
- NSData *imageRepresentation = [image representationWithFileType:bestType maximumFileSize:PIC_IM_MAX_SIZE];
+ if (imageRepresentation.length > PIC_IM_MAX_SIZE) {
+ imageRepresentation = [image representationWithFileType:bestType maximumFileSize:PIC_IM_MAX_SIZE];
+ }
if (!imageRepresentation) {
[uploader errorWithMessage:AILocalizedString(@"Unable to upload", nil) forChat:chat];
More information about the commits
mailing list