Skip to content

Commit bf3607f

Browse files
authored
Merge pull request #1 from SDWebImage/feature_cache_cost_function
Adopt SDWebImage's memory cache cost function
2 parents 42bbc19 + 465efff commit bf3607f

File tree

3 files changed

+37
-38
lines changed

3 files changed

+37
-38
lines changed

Example/Podfile.lock

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ PODS:
22
- Expecta (1.0.6)
33
- SDWebImage/Core (5.0.0-beta3)
44
- SDWebImageYYPlugin (0.1.1):
5-
- SDWebImage/Core (>= 5.0.0-beta)
5+
- SDWebImage/Core (>= 5.0.0-beta3)
66
- SDWebImageYYPlugin/YYCache (= 0.1.1)
77
- SDWebImageYYPlugin/YYImage (= 0.1.1)
88
- SDWebImageYYPlugin/YYCache (0.1.1):
9-
- SDWebImage/Core (>= 5.0.0-beta)
9+
- SDWebImage/Core (>= 5.0.0-beta3)
1010
- YYCache
1111
- SDWebImageYYPlugin/YYImage (0.1.1):
12-
- SDWebImage/Core (>= 5.0.0-beta)
12+
- SDWebImage/Core (>= 5.0.0-beta3)
1313
- YYImage/Core
1414
- YYCache (1.0.4)
1515
- YYImage/Core (1.0.4)
@@ -22,12 +22,18 @@ DEPENDENCIES:
2222
- SDWebImageYYPlugin (from `../`)
2323
- YYImage/WebP
2424

25+
SPEC REPOS:
26+
https://github.com/cocoapods/specs.git:
27+
- Expecta
28+
- YYCache
29+
- YYImage
30+
2531
EXTERNAL SOURCES:
2632
SDWebImage:
2733
:branch: 5.x
2834
:git: https://github.com/rs/SDWebImage.git
2935
SDWebImageYYPlugin:
30-
:path: ../
36+
:path: "../"
3137

3238
CHECKOUT OPTIONS:
3339
SDWebImage:
@@ -37,10 +43,10 @@ CHECKOUT OPTIONS:
3743
SPEC CHECKSUMS:
3844
Expecta: 3b6bd90a64b9a1dcb0b70aa0e10a7f8f631667d5
3945
SDWebImage: e52654ceef9fdc19f4c612d64a5b6d3f05dd81a4
40-
SDWebImageYYPlugin: cfaeb2f2834c161d9aa9949d3d7c44aa7c80463c
46+
SDWebImageYYPlugin: 3a0cc67eb20702c7db4f66b568eff30ba058e726
4147
YYCache: 8105b6638f5e849296c71f331ff83891a4942952
4248
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
4349

4450
PODFILE CHECKSUM: 5900612c85a696261bc740246922b2914976662c
4551

46-
COCOAPODS: 1.4.0
52+
COCOAPODS: 1.5.3

Example/SDWebImageYYPlugin.xcodeproj/project.pbxproj

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@
242242
6003F587195388D20070C39A /* Frameworks */,
243243
6003F588195388D20070C39A /* Resources */,
244244
A1C9798AC9A64B3285935ADE /* [CP] Embed Pods Frameworks */,
245-
0731EE8A10D058D3EFB2B75A /* [CP] Copy Pods Resources */,
246245
);
247246
buildRules = (
248247
);
@@ -262,7 +261,6 @@
262261
6003F5AB195388D20070C39A /* Frameworks */,
263262
6003F5AC195388D20070C39A /* Resources */,
264263
79112E8232AA29A2C856E6D2 /* [CP] Embed Pods Frameworks */,
265-
A1F76FB8CC168A22F62A2894 /* [CP] Copy Pods Resources */,
266264
);
267265
buildRules = (
268266
);
@@ -337,21 +335,6 @@
337335
/* End PBXResourcesBuildPhase section */
338336

339337
/* Begin PBXShellScriptBuildPhase section */
340-
0731EE8A10D058D3EFB2B75A /* [CP] Copy Pods Resources */ = {
341-
isa = PBXShellScriptBuildPhase;
342-
buildActionMask = 2147483647;
343-
files = (
344-
);
345-
inputPaths = (
346-
);
347-
name = "[CP] Copy Pods Resources";
348-
outputPaths = (
349-
);
350-
runOnlyForDeploymentPostprocessing = 0;
351-
shellPath = /bin/sh;
352-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SDWebImageYYPlugin_Example/Pods-SDWebImageYYPlugin_Example-resources.sh\"\n";
353-
showEnvVarsInLog = 0;
354-
};
355338
0C5606D06E2CBD1FF0BCA1FB /* [CP] Check Pods Manifest.lock */ = {
356339
isa = PBXShellScriptBuildPhase;
357340
buildActionMask = 2147483647;
@@ -430,21 +413,6 @@
430413
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SDWebImageYYPlugin_Example/Pods-SDWebImageYYPlugin_Example-frameworks.sh\"\n";
431414
showEnvVarsInLog = 0;
432415
};
433-
A1F76FB8CC168A22F62A2894 /* [CP] Copy Pods Resources */ = {
434-
isa = PBXShellScriptBuildPhase;
435-
buildActionMask = 2147483647;
436-
files = (
437-
);
438-
inputPaths = (
439-
);
440-
name = "[CP] Copy Pods Resources";
441-
outputPaths = (
442-
);
443-
runOnlyForDeploymentPostprocessing = 0;
444-
shellPath = /bin/sh;
445-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SDWebImageYYPlugin_Tests/Pods-SDWebImageYYPlugin_Tests-resources.sh\"\n";
446-
showEnvVarsInLog = 0;
447-
};
448416
/* End PBXShellScriptBuildPhase section */
449417

450418
/* Begin PBXSourcesBuildPhase section */

SDWebImageYYPlugin/Classes/YYImage/YYImageBridge/YYImage+SDAdditions.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,28 @@ - (BOOL)isAllFramesLoaded {
4040
}
4141

4242
@end
43+
44+
@implementation YYImage (MemoryCacheCost)
45+
46+
- (NSUInteger)sd_memoryCost {
47+
NSNumber *value = objc_getAssociatedObject(self, @selector(sd_memoryCost));
48+
if (value != nil) {
49+
return value.unsignedIntegerValue;
50+
}
51+
52+
CGImageRef imageRef = self.CGImage;
53+
if (!imageRef) {
54+
return 0;
55+
}
56+
NSUInteger bytesPerFrame = CGImageGetBytesPerRow(imageRef) * CGImageGetHeight(imageRef);
57+
NSUInteger frameCount = 1;
58+
if (self.isAllFramesLoaded) {
59+
frameCount = self.animatedImageFrameCount;
60+
}
61+
frameCount = frameCount > 0 ? frameCount : 1;
62+
NSUInteger cost = bytesPerFrame * frameCount;
63+
return cost;
64+
}
65+
66+
@end
67+

0 commit comments

Comments
 (0)