Skip to content

Commit

Permalink
Merge pull request #158 from Gottox/improve/lookup-extractor-once
Browse files Browse the repository at this point in the history
extract: lookup extractor implementation once
  • Loading branch information
Gottox authored Oct 25, 2023
2 parents 6284334 + e381e46 commit 6bb3a3c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions libsqsh/include/sqsh_extract_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ sqsh__extractor_impl_from_id(int id);
*/
SQSH_NO_EXPORT SQSH_NO_UNUSED int sqsh__extractor_init(
struct SqshExtractor *extractor, struct CxBuffer *buffer,
int algorithm_id, size_t block_size);
const struct SqshExtractorImpl *impl, size_t block_size);

/**
* @internal
Expand Down Expand Up @@ -176,7 +176,7 @@ struct SqshExtractManager {
* @privatesection
*/
struct CxRcHashMap hash_map;
unsigned int compression_id;
const struct SqshExtractorImpl *extractor_impl;
uint32_t block_size;
struct SqshMapManager *map_manager;
struct CxLru lru;
Expand Down
15 changes: 6 additions & 9 deletions libsqsh/src/extract/extract_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ sqsh__extract_manager_init(
const size_t lru_size =
SQSH_CONFIG_DEFAULT(config->compression_lru_size, 128);
const struct SqshSuperblock *superblock = sqsh_archive_superblock(archive);
enum SqshSuperblockCompressionId compression_id =
sqsh_superblock_compression_id(superblock);

if (sqsh__extractor_impl_from_id(
sqsh_superblock_compression_id(superblock)) == NULL) {
manager->extractor_impl = sqsh__extractor_impl_from_id(compression_id);
if (manager->extractor_impl == NULL) {
return -SQSH_ERROR_COMPRESSION_UNSUPPORTED;
}

Expand All @@ -117,10 +119,6 @@ sqsh__extract_manager_init(
}
manager->map_manager = sqsh_archive_map_manager(archive);

enum SqshSuperblockCompressionId compression_id =
sqsh_superblock_compression_id(superblock);

manager->compression_id = compression_id;
manager->block_size = block_size;

out:
Expand All @@ -136,8 +134,7 @@ sqsh__extract_manager_uncompress(
const struct CxBuffer **target) {
int rv = 0;
struct SqshExtractor extractor = {0};
const enum SqshSuperblockCompressionId compression_id =
manager->compression_id;
const struct SqshExtractorImpl *extractor_impl = manager->extractor_impl;
const uint32_t block_size = manager->block_size;

rv = sqsh__mutex_lock(&manager->lock);
Expand All @@ -159,7 +156,7 @@ sqsh__extract_manager_uncompress(
const uint8_t *data = sqsh__map_reader_data(reader);

rv = sqsh__extractor_init(
&extractor, &buffer, compression_id, block_size);
&extractor, &buffer, extractor_impl, block_size);
if (rv < 0) {
goto out;
}
Expand Down
4 changes: 1 addition & 3 deletions libsqsh/src/extract/extractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ sqsh__extractor_impl_from_id(int id) {
int
sqsh__extractor_init(
struct SqshExtractor *extractor, struct CxBuffer *buffer,
int algorithm_id, size_t block_size) {
const struct SqshExtractorImpl *impl, size_t block_size) {
int rv = 0;
const struct SqshExtractorImpl *impl =
sqsh__extractor_impl_from_id(algorithm_id);
if (impl == NULL) {
rv = -SQSH_ERROR_COMPRESSION_UNSUPPORTED;
goto out;
Expand Down

0 comments on commit 6bb3a3c

Please sign in to comment.