Skip to content

Commit f3aad3f

Browse files
committed
Grow maximum count to be at least the count of entries that will fit in a chunk.
1 parent b170cd2 commit f3aad3f

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

FastImageCache/FICImageTable.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ - (instancetype)initWithFormat:(FICImageFormat *)imageFormat {
162162
NSInteger goalChunkLength = 2 * (1024 * 1024);
163163
NSInteger goalEntriesPerChunk = goalChunkLength / _entryLength;
164164
_entriesPerChunk = MAX(4, goalEntriesPerChunk);
165+
if ([self _maximumCount] > [_imageFormat maximumCount]) {
166+
NSString *message = [NSString stringWithFormat:@"*** FIC Warning: growing desired maximumCount (%d) for format %@ to fill a chunk (%d)", [_imageFormat maximumCount], [_imageFormat name], [self _maximumCount]];
167+
[[FICImageCache sharedImageCache] _logMessage:message];
168+
}
165169
_chunkLength = (size_t)(_entryLength * _entriesPerChunk);
166170

167171
_fileLength = lseek(_fileDescriptor, 0, SEEK_END);
@@ -400,6 +404,10 @@ - (BOOL)entryExistsForEntityUUID:(NSString *)entityUUID sourceImageUUID:(NSStrin
400404

401405
#pragma mark - Working with Entries
402406

407+
- (int)_maximumCount {
408+
return MAX([_imageFormat maximumCount], _entriesPerChunk);
409+
}
410+
403411
- (void)_setEntryCount:(NSInteger)entryCount {
404412
if (entryCount != _entryCount) {
405413
off_t fileLength = entryCount * _entryLength;
@@ -449,12 +457,12 @@ - (NSInteger)_nextEntryIndex {
449457
index = _entryCount;
450458
}
451459

452-
if (index >= [_imageFormat maximumCount] && [_MRUEntries count]) {
460+
if (index >= [self _maximumCount] && [_MRUEntries count]) {
453461
// Evict the oldest/least-recently accessed entry here
454462
[self deleteEntryForEntityUUID:[_MRUEntries lastObject]];
455463
index = [self _nextEntryIndex];
456464
}
457-
465+
458466
return index;
459467
}
460468

0 commit comments

Comments
 (0)