From 2b401ce13b4c45c91ee53116d8aba270822823e9 Mon Sep 17 00:00:00 2001
From: twinaphex <libretro@gmail.com>
Date: Sat, 27 Apr 2019 02:39:33 +0200
Subject: [PATCH] (archive_file) Small optimizations - use one strlen less in
 one instance

---
 libretro-common/file/archive_file.c      | 64 ++++++++++--------------
 libretro-common/file/archive_file_zlib.c |  3 +-
 2 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/libretro-common/file/archive_file.c b/libretro-common/file/archive_file.c
index fe0f8a1443..690f18a12b 100644
--- a/libretro-common/file/archive_file.c
+++ b/libretro-common/file/archive_file.c
@@ -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)
-      ext_list = string_split(valid_exts, "|");
-
-   if (ext_list)
    {
-      const char *file_ext         = NULL;
+      size_t path_len              = strlen(path);
       /* Checks if this entry is a directory or a file. */
-      char last_char = path[path_len-1];
+      char last_char               = path[path_len - 1];
+      struct string_list *ext_list = NULL;
 
       /* Skip if directory. */
       if (last_char == '/' || last_char == '\\' )
-         goto error;
-
-      file_ext = path_get_extension(path);
-
-      if (!file_ext)
-         goto error;
-
-      if (!string_list_find_elem_prefix(ext_list, ".", file_ext))
       {
-         /* keep iterating */
-         ret = -1;
-         goto error;
+         string_list_free(ext_list);
+         return 0;
       }
+      
+      ext_list                = string_split(valid_exts, "|");
 
-      attr.i = RARCH_COMPRESSED_FILE_IN_ARCHIVE;
-      string_list_free(ext_list);
+      if (ext_list)
+      {
+         const char *file_ext = path_get_extension(path);
+
+         if (!file_ext)
+         {
+            string_list_free(ext_list);
+            return 0;
+         }
+
+         if (!string_list_find_elem_prefix(ext_list, ".", file_ext))
+         {
+            /* keep iterating */
+            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;
 
diff --git a/libretro-common/file/archive_file_zlib.c b/libretro-common/file/archive_file_zlib.c
index 3de1d445b3..5077ebe201 100644
--- a/libretro-common/file/archive_file_zlib.c
+++ b/libretro-common/file/archive_file_zlib.c
@@ -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))