Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched hash for an implementation of MD5 cache to great unique URL keys #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Demo/EGOImageLoadingDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
28BBA36B10C62E3300081AB5 /* EGOImageLoadConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 28BBA36A10C62E3300081AB5 /* EGOImageLoadConnection.m */; };
28C286E10D94DF7D0034E888 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28C286E00D94DF7D0034E888 /* RootViewController.m */; };
28F335F11007B36200424DE2 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28F335F01007B36200424DE2 /* RootViewController.xib */; };
66FE1FE81416232400D3295C /* NSString+MD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 66FE1FE71416232400D3295C /* NSString+MD5.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -54,6 +55,8 @@
28C286E00D94DF7D0034E888 /* RootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = "<group>"; };
28F335F01007B36200424DE2 /* RootViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RootViewController.xib; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
66FE1FE61416232400D3295C /* NSString+MD5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MD5.h"; sourceTree = "<group>"; };
66FE1FE71416232400D3295C /* NSString+MD5.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MD5.m"; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* EGOImageLoadingDemo-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "EGOImageLoadingDemo-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -131,6 +134,8 @@
2826AB15108D4295007FBD1D /* EGOImageLoader.m */,
28BBA36910C62E3300081AB5 /* EGOImageLoadConnection.h */,
28BBA36A10C62E3300081AB5 /* EGOImageLoadConnection.m */,
66FE1FE61416232400D3295C /* NSString+MD5.h */,
66FE1FE71416232400D3295C /* NSString+MD5.m */,
);
name = EGOImageLoader;
path = ../EGOImageLoader;
Expand Down Expand Up @@ -264,6 +269,7 @@
2826AB50108D4295007FBD1D /* EGOImageView.m in Sources */,
2826AB8E108D5160007FBD1D /* ExampleCell.m in Sources */,
28BBA36B10C62E3300081AB5 /* EGOImageLoadConnection.m in Sources */,
66FE1FE81416232400D3295C /* NSString+MD5.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 3 additions & 2 deletions EGOImageLoader/EGOImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
#import "EGOImageLoader.h"
#import "EGOImageLoadConnection.h"
#import "EGOCache.h"
#import "NSString+MD5.h"

static EGOImageLoader* __imageLoader;

inline static NSString* keyForURL(NSURL* url, NSString* style) {
if(style) {
return [NSString stringWithFormat:@"EGOImageLoader-%u-%u", [[url description] hash], [style hash]];
return [NSString stringWithFormat:@"EGOImageLoader-%@-%@", [[url description] md5Hash], [style md5Hash]];
} else {
return [NSString stringWithFormat:@"EGOImageLoader-%u", [[url description] hash]];
return [NSString stringWithFormat:@"EGOImageLoader-%@", [[url description] md5Hash]];
}
}

Expand Down
12 changes: 12 additions & 0 deletions EGOImageLoader/NSString+MD5.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// NSString+MD5.h
// EGOImageLoading
//

#import <Foundation/Foundation.h>

@interface NSString (MD5)

- (NSString *)md5Hash;

@end
25 changes: 25 additions & 0 deletions EGOImageLoader/NSString+MD5.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// NSString+MD5.m
// EGOImageLoading
//

#import "NSString+MD5.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (MD5)

- (NSString *)md5Hash {

const char *cStr = [self UTF8String];
unsigned char result[16];
CC_MD5( cStr, strlen(cStr), result );
return [NSString stringWithFormat:
@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}

@end