• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BathyScapheで画像のインラインプレビューを可能にするプラグイン


コミットメタ情報

リビジョン80c6b52bc2ab171a491b8d7aeb5d62e5838efce3 (tree)
日時2012-05-18 23:16:01
作者masakih <masakih@user...>
コミッターmasakih

ログメッセージ

[Mod] NSCacheを使用するようにした

merge from extended

変更サマリ

差分

--- a/BSInlinePreviewer.h
+++ b/BSInlinePreviewer.h
@@ -45,3 +45,5 @@
4545 - (id)previewAttributes;
4646
4747 @end
48+
49+extern NSString *const BSInlinePreviewerPreviewed;
--- a/BSInlinePreviewer.m
+++ b/BSInlinePreviewer.m
@@ -29,7 +29,7 @@
2929
3030 @implementation BSInlinePreviewer
3131
32-static NSString *const BSInlinePreviewerPreviewed = @"BSInlinePreviewerPreviewed";
32+NSString *const BSInlinePreviewerPreviewed = @"BSInlinePreviewerPreviewed";
3333 const NSUInteger alreadyPreviewed = NSNotFound - 1;
3434
3535 @synthesize totalDownloads, remainder;
@@ -43,6 +43,7 @@ const NSUInteger alreadyPreviewed = NSNotFound - 1;
4343 [self setPreferences:prefs];
4444 cache = [[NSCache alloc] init];
4545 [cache setName:@"BSInlinePreviewer"];
46+ [cache setCountLimit:100];
4647 }
4748
4849 return self;
@@ -441,7 +442,7 @@ const NSUInteger alreadyPreviewed = NSNotFound - 1;
441442 - (NSImage *)downloadImageURL:(NSURL *)imageURL
442443 {
443444 NSImage *cachedImage = [cache objectForKey:[self cacheKeyForURL:imageURL]];
444- if(cachedImage) return [self fitImage:cachedImage toSize:[self previewSize]];;
445+ if(cachedImage) return cachedImage;
445446
446447 NSURLRequest *req;
447448
@@ -457,24 +458,27 @@ const NSUInteger alreadyPreviewed = NSNotFound - 1;
457458 error:&err];
458459 if(err) {
459460 NSLog(@"Fail download. reason(%@)", [err localizedDescription]);
460- return [self notFoundImage];
461+ goto notFound;
461462 }
462463 if(res) {
463464 if(![[res MIMEType] hasPrefix:@"image/"]) {
464465 NSLog(@"Fail download. reason(target type is %@)", [res MIMEType]);
465- return [self notFoundImage];
466+ goto notFound;
466467 }
467468 }
468469
469470 NSImage *image = [[[NSImage alloc] initWithData:imageData] autorelease];
470471 if(!image) {
471472 NSLog(@"Can not create image.");
472- return [self notFoundImage];
473+ goto notFound;
473474 }
474475
475- [cache setObject:image forKey:[self cacheKeyForURL:imageURL]];
476-
477- return [self fitImage:image toSize:[self previewSize]];
476+ cachedImage = [self fitImage:image toSize:[self previewSize]];
477+ [cache setObject:cachedImage forKey:[self cacheKeyForURL:imageURL]];
478+ return cachedImage;
479+notFound:
480+ [cache setObject:[self notFoundImage] forKey:[self cacheKeyForURL:imageURL]];
481+ return [self notFoundImage];
478482 }
479483
480484 @end