From 5a1cdfc72c1abd64a1a44955a3f43a1cbcba9876 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 30 Sep 2017 15:03:28 +0300 Subject: [PATCH] rename arena->blocks to arena->blocks_pool fix comments --- libImaging/Imaging.h | 10 +++++----- libImaging/Storage.c | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index c1a041248..626ed8337 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -160,14 +160,14 @@ struct ImagingPaletteInstance { typedef struct ImagingMemoryArena { int alignment; /* Alignment in memory of each line of an image */ - int block_size; /* Preferred block size */ + int block_size; /* Preferred block size, bytes */ int blocks_max; /* Maximum number of cached blocks */ - int blocks_cached; /* Current number of block not accociated with images */ - ImagingMemoryBlock *blocks; + int blocks_cached; /* Current number of blocks not associated with images */ + ImagingMemoryBlock *blocks_pool; int stats_new_count; /* Number of new allocated images */ int stats_allocated_blocks; /* Number of allocated blocks */ - int stats_reused_blocks; /* Number of blocks which was retrieved from pool */ - int stats_reallocated_blocks; /* Number of blocks which was actually reallocated after retrieving */ + int stats_reused_blocks; /* Number of blocks which were retrieved from a pool */ + int stats_reallocated_blocks; /* Number of blocks which were actually reallocated after retrieving */ int stats_freed_blocks; /* Number of freed blocks */ } *ImagingMemoryArena; diff --git a/libImaging/Storage.c b/libImaging/Storage.c index 0f0ace826..4ec404484 100644 --- a/libImaging/Storage.c +++ b/libImaging/Storage.c @@ -271,7 +271,7 @@ struct ImagingMemoryArena ImagingDefaultArena = { 16*1024*1024, // block_size 0, // blocks_max 0, // blocks_cached - NULL, // blocks + NULL, // blocks_pool 0, 0, 0, 0, 0 // Stats }; @@ -282,19 +282,19 @@ ImagingMemorySetBlocksMax(ImagingMemoryArena arena, int blocks_max) /* Free already cached blocks */ ImagingMemoryClearCache(arena, blocks_max); - if (blocks_max == 0 && arena->blocks != NULL) { - free(arena->blocks); - arena->blocks = NULL; - } else if (arena->blocks != NULL) { - p = realloc(arena->blocks, sizeof(*arena->blocks) * blocks_max); + if (blocks_max == 0 && arena->blocks_pool != NULL) { + free(arena->blocks_pool); + arena->blocks_pool = NULL; + } else if (arena->blocks_pool != NULL) { + p = realloc(arena->blocks_pool, sizeof(*arena->blocks_pool) * blocks_max); if ( ! p) { // Leave previous blocks_max value return 0; } - arena->blocks = p; + arena->blocks_pool = p; } else { - arena->blocks = calloc(sizeof(*arena->blocks), blocks_max); - if ( ! arena->blocks) { + arena->blocks_pool = calloc(sizeof(*arena->blocks_pool), blocks_max); + if ( ! arena->blocks_pool) { return 0; } } @@ -308,7 +308,7 @@ ImagingMemoryClearCache(ImagingMemoryArena arena, int new_size) { while (arena->blocks_cached > new_size) { arena->blocks_cached -= 1; - free(arena->blocks[arena->blocks_cached].ptr); + free(arena->blocks_pool[arena->blocks_cached].ptr); arena->stats_freed_blocks += 1; } } @@ -321,14 +321,14 @@ memory_get_block(ImagingMemoryArena arena, int requested_size, int dirty) if (arena->blocks_cached > 0) { // Get block from cache arena->blocks_cached -= 1; - block = arena->blocks[arena->blocks_cached]; + block = arena->blocks_pool[arena->blocks_cached]; // Reallocate if needed if (block.size != requested_size){ block.ptr = realloc(block.ptr, requested_size); } if ( ! block.ptr) { // Can't allocate, free prevous pointer (it is still valid) - free(arena->blocks[arena->blocks_cached].ptr); + free(arena->blocks_pool[arena->blocks_cached].ptr); arena->stats_freed_blocks += 1; return block; } @@ -336,7 +336,7 @@ memory_get_block(ImagingMemoryArena arena, int requested_size, int dirty) memset(block.ptr, 0, requested_size); } arena->stats_reused_blocks += 1; - if (block.ptr != arena->blocks[arena->blocks_cached].ptr) { + if (block.ptr != arena->blocks_pool[arena->blocks_cached].ptr) { arena->stats_reallocated_blocks += 1; } } else { @@ -360,7 +360,7 @@ memory_return_block(ImagingMemoryArena arena, ImagingMemoryBlock block) block.size = arena->block_size; block.ptr = realloc(block.ptr, arena->block_size); } - arena->blocks[arena->blocks_cached] = block; + arena->blocks_pool[arena->blocks_cached] = block; arena->blocks_cached += 1; } else { free(block.ptr); @@ -390,7 +390,7 @@ ImagingAllocateArray(Imaging im, int dirty, int block_size) ImagingMemoryArena arena = &ImagingDefaultArena; ImagingMemoryBlock block = {NULL, 0}; int aligned_linesize, lines_per_block, blocks_count; - char *aligned_ptr; + char *aligned_ptr = NULL; /* 0-width or 0-height image. No need to do anything */ if ( ! im->linesize || ! im->ysize) {