Fix #1366, addresses #1350 and reverts a part of #1221 - from commit 6406d8e, the wrong usage of dispatch_apply
This commit is contained in:
parent
ee49d49d35
commit
cac21e106d
|
|
@ -112,29 +112,14 @@
|
||||||
self.completionBlock = completionBlock;
|
self.completionBlock = completionBlock;
|
||||||
self.progressBlock = progressBlock;
|
self.progressBlock = progressBlock;
|
||||||
|
|
||||||
__weak SDWebImagePrefetcher *weakSelf = self;
|
|
||||||
|
|
||||||
if (urls.count == 0) {
|
if (urls.count == 0) {
|
||||||
if (completionBlock) {
|
if (completionBlock) {
|
||||||
completionBlock(0,0);
|
completionBlock(0,0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// http://oleb.net/blog/2013/07/parallelize-for-loops-gcd-dispatch_apply/
|
// Starts prefetching from the very first image on the list with the max allowed concurrency
|
||||||
// Optimize the maxConcurrentdownloads for effeciency. Since caching operations are involved that are non-trivial using
|
NSUInteger listCount = self.prefetchURLs.count;
|
||||||
// dispatch_apply might be helpful.
|
for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
|
||||||
|
|
||||||
NSInteger maxNumberOfImages = self.prefetchURLs.count;
|
|
||||||
|
|
||||||
dispatch_apply(maxNumberOfImages/self.maxConcurrentDownloads, self.prefetcherQueue, ^(size_t index) {
|
|
||||||
size_t i = index * self.maxConcurrentDownloads;
|
|
||||||
size_t stop = i + self.maxConcurrentDownloads;
|
|
||||||
do {
|
|
||||||
[weakSelf startPrefetchingAtIndex:i++];
|
|
||||||
} while (i < stop);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Download remaining images.
|
|
||||||
for (size_t i = maxNumberOfImages - (maxNumberOfImages % self.maxConcurrentDownloads); i < (size_t)maxNumberOfImages; i++) {
|
|
||||||
[self startPrefetchingAtIndex:i];
|
[self startPrefetchingAtIndex:i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue