Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ios
/
yh_sdwebimage
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
Syo Ikeda
10 years ago
Commit
021607a84543012847af6eef9d5add3ce295567a
1 parent
d41bfaf8
[Refactor] Implement cache cost calculation as a inline function
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
SDWebImage/SDImageCache.m
SDWebImage/SDImageCache.m
View file @
021607a
...
...
@@ -29,6 +29,10 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
return
NO
;
}
FOUNDATION_STATIC_INLINE
NSUInteger
SDCacheCostForImage
(
UIImage
*
image
)
{
return
image
.
size
.
height
*
image
.
size
.
width
*
image
.
scale
*
image
.
scale
;
}
@interface
SDImageCache
()
@property
(
strong
,
nonatomic
)
NSCache
*
memCache
;
...
...
@@ -152,7 +156,8 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
return
;
}
[
self
.
memCache
setObject
:
image
forKey
:
key
cost
:
image
.
size
.
height
*
image
.
size
.
width
*
image
.
scale
*
image
.
scale
];
NSUInteger
cost
=
SDCacheCostForImage
(
image
);
[
self
.
memCache
setObject
:
image
forKey
:
key
cost
:
cost
];
if
(
toDisk
)
{
dispatch_async
(
self
.
ioQueue
,
^
{
...
...
@@ -239,7 +244,7 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
// Second check the disk cache...
UIImage
*
diskImage
=
[
self
diskImageForKey
:
key
];
if
(
diskImage
)
{
CGFloat
cost
=
diskImage
.
size
.
height
*
diskImage
.
size
.
width
*
diskImage
.
scale
*
diskImage
.
scale
;
NSUInteger
cost
=
SDCacheCostForImage
(
diskImage
)
;
[
self
.
memCache
setObject
:
diskImage
forKey
:
key
cost
:
cost
];
}
...
...
@@ -309,7 +314,7 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
@autoreleasepool
{
UIImage
*
diskImage
=
[
self
diskImageForKey
:
key
];
if
(
diskImage
)
{
CGFloat
cost
=
diskImage
.
size
.
height
*
diskImage
.
size
.
width
*
diskImage
.
scale
*
diskImage
.
scale
;
NSUInteger
cost
=
SDCacheCostForImage
(
diskImage
)
;
[
self
.
memCache
setObject
:
diskImage
forKey
:
key
cost
:
cost
];
}
...
...
Please
register
or
login
to post a comment