Skip to content

Commit

Permalink
Merge pull request #50 from Gottox/refactor/remove-skip-functions
Browse files Browse the repository at this point in the history
remove skip functions from iterators.
  • Loading branch information
Gottox authored Aug 21, 2023
2 parents 5ef4f38 + 42e7a78 commit 5972904
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 124 deletions.
18 changes: 0 additions & 18 deletions include/sqsh_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,6 @@ struct SqshFileIterator;
SQSH_NO_UNUSED struct SqshFileIterator *
sqsh_file_iterator_new(const struct SqshFile *file, int *err);

/**
* @brief Skips a certain amount of data in the file iterator. Keep in mind
* that calling this function will invalidate the data pointer returned by
* sqsh_file_iterator_data(). You should call sqsh_file_iterator_next() after
* calling this function to get a new data pointer.
*
* @memberof SqshFileIterator
*
* @param[in,out] iterator The file iterator to skip data in.
* @param[in] amount The amount of data to skip.
* @param[in] desired_size The desired size of the data to read. May be more or
* less than the actual size of the data read.
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_file_iterator_skip(
struct SqshFileIterator *iterator, size_t amount, size_t desired_size);

/**
* @brief Reads a certain amount of data from the file iterator.
* @memberof SqshFileIterator
Expand Down
14 changes: 0 additions & 14 deletions include/sqsh_mapper_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,20 +399,6 @@ SQSH_NO_EXPORT SQSH_NO_UNUSED int sqsh__map_iterator_init(
SQSH_NO_EXPORT SQSH_NO_UNUSED int
sqsh__map_iterator_next(struct SqshMapIterator *iterator);

/**
* @internal
* @memberof SqshMapIterator
* @brief Moves the iterator an arbitrary number of chunks forward.
* `sqsh__map_iterator_skip(iter, 1);` is equivalent to
* `sqsh__map_iterator_next(iter);`.
*
* @param[in] iterator The SqshMapIterator instance.
* @param[in] amount The number of chunks to skip.
* @return Returns 0 on success, a negative value on error.
*/
SQSH_NO_EXPORT SQSH_NO_UNUSED int
sqsh__map_iterator_skip(struct SqshMapIterator *iterator, size_t amount);

/**
* @internal
* @memberof SqshMapIterator
Expand Down
13 changes: 0 additions & 13 deletions include/sqsh_metablock_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@ SQSH_NO_EXPORT SQSH_NO_UNUSED int sqsh__metablock_iterator_init(
struct SqshMetablockIterator *iterator, struct SqshArchive *sqsh,
uint64_t start_address, uint64_t upper_limit);

/**
* @internal
* @memberof SqshMetablockIterator
* @brief skip several metablocks. sqsh__metablock_iterator_skip(i, 1) is
* equivalent to sqsh__metablock_iterator_next(i).
*
* @param[in,out] iterator The iterator to advance.
* @param[in] amount The number of metablocks to skip.
* @return 0 on success, or a negative value on error.
*/
SQSH_NO_EXPORT SQSH_NO_UNUSED int sqsh__metablock_iterator_skip(
struct SqshMetablockIterator *iterator, size_t amount);

/**
* @internal
* @memberof SqshMetablockIterator
Expand Down
30 changes: 0 additions & 30 deletions lib/file/file_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,36 +294,6 @@ sqsh_file_iterator_next(
}
}

int
sqsh_file_iterator_skip(
struct SqshFileIterator *iterator, size_t amount, size_t desired_size) {
int rv = 0;
if (amount == 0) {
return 0;
}

// TODO: do not actually map the blocks, just skip them
for (size_t i = 0; i < amount - 1; i++) {
rv = sqsh_file_iterator_next(iterator, 1);
if (rv < 0) {
goto out;
} else if (rv == 0) {
rv = -SQSH_ERROR_OUT_OF_BOUNDS;
goto out;
}
}

rv = sqsh_file_iterator_next(iterator, desired_size);
if (rv < 0) {
goto out;
} else if (rv == 0) {
rv = -SQSH_ERROR_OUT_OF_BOUNDS;
goto out;
}
out:
return rv;
}

const uint8_t *
sqsh_file_iterator_data(const struct SqshFileIterator *iterator) {
return iterator->data;
Expand Down
10 changes: 1 addition & 9 deletions lib/mapper/map_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,9 @@ sqsh__map_iterator_init(

int
sqsh__map_iterator_next(struct SqshMapIterator *iterator) {
return sqsh__map_iterator_skip(iterator, 1);
}

int
sqsh__map_iterator_skip(struct SqshMapIterator *iterator, size_t amount) {
int rv;

if (amount == 0) {
return 1;
}
iterator->index += amount;
iterator->index++;
if (iterator->mapping == NULL) {
iterator->index -= 1;
}
Expand Down
40 changes: 0 additions & 40 deletions lib/metablock/metablock_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,46 +119,6 @@ sqsh__metablock_iterator_next(struct SqshMetablockIterator *iterator) {
return rv;
}

int
sqsh__metablock_iterator_skip(
struct SqshMetablockIterator *iterator, size_t amount) {
int rv = 0;
uint16_t size = iterator->outer_size;

if (amount == 0) {
return 0;
}

for (sqsh_index_t i = 0; i < amount - 1; i++) {
int rv = 0;

rv = sqsh__map_reader_advance(
&iterator->reader, size, SQSH_SIZEOF_METABLOCK);
if (rv < 0) {
goto out;
}

const struct SqshDataMetablock *metablock =
(struct SqshDataMetablock *)sqsh__map_reader_data(
&iterator->reader);
size = sqsh__data_metablock_size(metablock);
if (size > SQSH_METABLOCK_BLOCK_SIZE) {
rv = -SQSH_ERROR_SIZE_MISMATCH;
goto out;
}
rv = sqsh__map_reader_advance(
&iterator->reader, SQSH_SIZEOF_METABLOCK, 0);
if (rv < 0) {
goto out;
}
}
iterator->outer_size = size;

rv = sqsh__metablock_iterator_next(iterator);
out:
return rv;
}

const uint8_t *
sqsh__metablock_iterator_data(const struct SqshMetablockIterator *iterator) {
return iterator->data;
Expand Down

0 comments on commit 5972904

Please sign in to comment.