(archive_file) Small optimizations - use one strlen less in one instance

This commit is contained in:
twinaphex 2019-04-27 02:39:33 +02:00
parent 7af68ca0b9
commit 2b401ce13b
2 changed files with 29 additions and 38 deletions

View File

@ -162,55 +162,47 @@ static int file_archive_get_file_list_cb(
struct archive_extract_userdata *userdata)
{
union string_list_elem_attr attr;
int ret = 0;
struct string_list *ext_list = NULL;
size_t path_len = strlen(path);
(void)cdata;
(void)cmode;
(void)csize;
(void)size;
(void)checksum;
attr.i = 0;
if (!path_len)
return 0;
if (valid_exts)
{
size_t path_len = strlen(path);
/* Checks if this entry is a directory or a file. */
char last_char = path[path_len - 1];
struct string_list *ext_list = NULL;
/* Skip if directory. */
if (last_char == '/' || last_char == '\\' )
{
string_list_free(ext_list);
return 0;
}
ext_list = string_split(valid_exts, "|");
if (ext_list)
{
const char *file_ext = NULL;
/* Checks if this entry is a directory or a file. */
char last_char = path[path_len-1];
/* Skip if directory. */
if (last_char == '/' || last_char == '\\' )
goto error;
file_ext = path_get_extension(path);
const char *file_ext = path_get_extension(path);
if (!file_ext)
goto error;
{
string_list_free(ext_list);
return 0;
}
if (!string_list_find_elem_prefix(ext_list, ".", file_ext))
{
/* keep iterating */
ret = -1;
goto error;
string_list_free(ext_list);
return -1;
}
attr.i = RARCH_COMPRESSED_FILE_IN_ARCHIVE;
string_list_free(ext_list);
}
}
return string_list_append(userdata->list, path, attr);
error:
string_list_free(ext_list);
return ret;
}
static int file_archive_extract_cb(const char *name, const char *valid_exts,
@ -414,9 +406,7 @@ int file_archive_parse_file_iterate(
valid_exts, userdata, file_cb);
if (ret != 1)
{
state->type = ARCHIVE_TRANSFER_DEINIT;
}
if (ret == -1)
state->type = ARCHIVE_TRANSFER_DEINIT_ERROR;

View File

@ -182,8 +182,9 @@ static int zip_file_decompressed(
uint32_t csize, uint32_t size,
uint32_t crc32, struct archive_extract_userdata *userdata)
{
char last_char = name[strlen(name) - 1];
/* Ignore directories. */
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
if (last_char == '/' || last_char == '\\')
return 1;
if (strstr(name, userdata->decomp_state.needle))