From 82efa5a3d6dd786d718ce1bcf38f6192454c5280 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Fri, 26 Aug 2022 13:55:52 +0200 Subject: [PATCH] (RJSON) Combine multiple consecutive rjsonwriter_raw calls into one - significantly reduces the amount of function calls --- core_info.c | 202 ++++++++++--------------------- disk_index_file.c | 23 ++-- playlist.c | 250 ++++++++++++--------------------------- runtime_file.c | 21 ++-- tasks/task_translation.c | 34 ++---- 5 files changed, 165 insertions(+), 365 deletions(-) diff --git a/core_info.c b/core_info.c index 58d329e55b..6c834656ce 100644 --- a/core_info.c +++ b/core_info.c @@ -862,21 +862,15 @@ static bool core_info_cache_write(core_info_cache_list_t *list, const char *info rjsonwriter_set_options(writer, RJSONWRITER_OPTION_SKIP_WHITESPACE); #endif - rjsonwriter_raw(writer, "{", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "version"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, CORE_INFO_CACHE_VERSION); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "items"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); - rjsonwriter_raw(writer, "[", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ": [\n", 4); for (i = 0; i < list->length; i++) { @@ -886,167 +880,124 @@ static bool core_info_cache_write(core_info_cache_list_t *list, const char *info continue; if (i > 0) - { - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); - } + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 4); - rjsonwriter_raw(writer, "{", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "display_name"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->display_name); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "display_version"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->display_version); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "core_name"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->core_name); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "system_manufacturer"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->system_manufacturer); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "systemname"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->systemname); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "system_id"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->system_id); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "supported_extensions"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->supported_extensions); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "authors"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->authors); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "permissions"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->permissions); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "licenses"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->licenses); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "categories"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->categories); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "databases"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->databases); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "notes"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->notes); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "required_hw_api"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->required_hw_api); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "description"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->description); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); if (info->firmware_count > 0) { rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "firmware"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); - rjsonwriter_raw(writer, "[", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ": [\n", 4); for (j = 0; j < info->firmware_count; j++) { rjsonwriter_add_spaces(writer, 8); - rjsonwriter_raw(writer, "{", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); rjsonwriter_add_spaces(writer, 10); rjsonwriter_add_string(writer, "path"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->firmware[j].path); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 10); rjsonwriter_add_string(writer, "desc"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->firmware[j].desc); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 10); rjsonwriter_add_string(writer, "optional"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = info->firmware[j].optional; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); @@ -1062,100 +1013,78 @@ static bool core_info_cache_write(core_info_cache_list_t *list, const char *info } rjsonwriter_add_spaces(writer, 6); - rjsonwriter_raw(writer, "]", 1); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "],\n", 3); } rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "core_file_id"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ":\n", 2); rjsonwriter_add_spaces(writer, 6); - rjsonwriter_raw(writer, "{", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); rjsonwriter_add_spaces(writer, 8); rjsonwriter_add_string(writer, "str"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, info->core_file_id.str); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 8); rjsonwriter_add_string(writer, "hash"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", info->core_file_id.hash); rjsonwriter_raw(writer, "\n", 1); rjsonwriter_add_spaces(writer, 6); - rjsonwriter_raw(writer, "}", 1); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "},\n", 3); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "firmware_count"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", info->firmware_count); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "savestate_support_level"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", info->savestate_support_level); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "has_info"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = info->has_info; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); } - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "supports_no_game"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = info->supports_no_game; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); } - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "single_purpose"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = info->single_purpose; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); } - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "database_match_archive_member"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = info->database_match_archive_member; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); } - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "is_experimental"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = info->is_experimental; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); @@ -1168,10 +1097,7 @@ static bool core_info_cache_write(core_info_cache_list_t *list, const char *info rjsonwriter_raw(writer, "\n", 1); rjsonwriter_add_spaces(writer, 2); - rjsonwriter_raw(writer, "]", 1); - rjsonwriter_raw(writer, "\n", 1); - rjsonwriter_raw(writer, "}", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "]\n}\n", 4); rjsonwriter_free(writer); RARCH_LOG("[Core Info] Wrote to cache file: %s\n", file_path); diff --git a/disk_index_file.c b/disk_index_file.c index ba9a918c2b..e023f51747 100644 --- a/disk_index_file.c +++ b/disk_index_file.c @@ -392,38 +392,29 @@ bool disk_index_file_save(disk_index_file_t *disk_index_file) } /* Write output file */ - rjsonwriter_raw(writer, "{", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); /* > Version entry */ rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "version"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, "1.0"); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); /* > image index entry */ rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "image_index"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", disk_index_file->image_index); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); /* > image path entry */ rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "image_path"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, disk_index_file->image_path); - rjsonwriter_raw(writer, "\n", 1); - /* > Finalise */ - rjsonwriter_raw(writer, "}", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "\n}\n", 3); /* Free JSON writer */ if (!rjsonwriter_free(writer)) diff --git a/playlist.c b/playlist.c index 8734107331..0fc9401925 100644 --- a/playlist.c +++ b/playlist.c @@ -1505,112 +1505,82 @@ void playlist_write_runtime_file(playlist_t *playlist) goto end; } - rjsonwriter_raw(writer, "{", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "version"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, "1.0"); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "items"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); - rjsonwriter_raw(writer, "[", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ": [\n", 4); for (i = 0, len = RBUF_LEN(playlist->entries); i < len; i++) { rjsonwriter_add_spaces(writer, 4); - rjsonwriter_raw(writer, "{", 1); - - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "path"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].path); - rjsonwriter_raw(writer, ",", 1); - - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "core_path"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].core_path); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "runtime_hours"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].runtime_hours); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "runtime_minutes"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].runtime_minutes); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "runtime_seconds"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].runtime_seconds); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "last_played_year"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].last_played_year); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "last_played_month"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].last_played_month); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "last_played_day"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].last_played_day); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "last_played_hour"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].last_played_hour); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "last_played_minute"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].last_played_minute); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "last_played_second"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%u", playlist->entries[i].last_played_second); rjsonwriter_raw(writer, "\n", 1); @@ -1624,10 +1594,7 @@ void playlist_write_runtime_file(playlist_t *playlist) } rjsonwriter_add_spaces(writer, 2); - rjsonwriter_raw(writer, "]", 1); - rjsonwriter_raw(writer, "\n", 1); - rjsonwriter_raw(writer, "}", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "]\n}\n", 4); rjsonwriter_free(writer); playlist->modified = false; @@ -1727,153 +1694,118 @@ void playlist_write_file(playlist_t *playlist) if (compressed) rjsonwriter_set_options(writer, RJSONWRITER_OPTION_SKIP_WHITESPACE); - rjsonwriter_raw(writer, "{", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "version"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, "1.5"); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "default_core_path"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->default_core_path); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "default_core_name"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->default_core_name); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); if (!string_is_empty(playlist->base_content_directory)) { rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "base_content_directory"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->base_content_directory); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); } rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "label_display_mode"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%d", (int)playlist->label_display_mode); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "right_thumbnail_mode"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%d", (int)playlist->right_thumbnail_mode); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "left_thumbnail_mode"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%d", (int)playlist->left_thumbnail_mode); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "sort_mode"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%d", (int)playlist->sort_mode); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); if (!string_is_empty(playlist->scan_record.content_dir)) { rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "scan_content_dir"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->scan_record.content_dir); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "scan_file_exts"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->scan_record.file_exts); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "scan_dat_file_path"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->scan_record.dat_file_path); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "scan_search_recursively"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = playlist->scan_record.search_recursively; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); } - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "scan_search_archives"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = playlist->scan_record.search_archives; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); } - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "scan_filter_dat_content"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); { bool value = playlist->scan_record.filter_dat_content; rjsonwriter_raw(writer, (value ? "true" : "false"), (value ? 4 : 5)); } - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); } rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "items"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); - rjsonwriter_raw(writer, "[", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ": [\n", 4); for (i = 0, len = RBUF_LEN(playlist->entries); i < len; i++) { rjsonwriter_add_spaces(writer, 4); - rjsonwriter_raw(writer, "{", 1); - - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "path"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].path); rjsonwriter_raw(writer, ",", 1); @@ -1882,8 +1814,7 @@ void playlist_write_file(playlist_t *playlist) rjsonwriter_raw(writer, "\n", 1); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "entry_slot"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_rawf(writer, "%d", (int)playlist->entries[i].entry_slot); rjsonwriter_raw(writer, ",", 1); } @@ -1891,61 +1822,44 @@ void playlist_write_file(playlist_t *playlist) rjsonwriter_raw(writer, "\n", 1); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "label"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].label); - rjsonwriter_raw(writer, ",", 1); - - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "core_path"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].core_path); - rjsonwriter_raw(writer, ",", 1); - - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "core_name"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].core_name); - rjsonwriter_raw(writer, ",", 1); - - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "crc32"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].crc32); - rjsonwriter_raw(writer, ",", 1); - - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "db_name"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].db_name); if (!string_is_empty(playlist->entries[i].subsystem_ident)) { - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "subsystem_ident"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].subsystem_ident); } if (!string_is_empty(playlist->entries[i].subsystem_name)) { - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "subsystem_name"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, playlist->entries[i].subsystem_name); } @@ -1954,14 +1868,10 @@ void playlist_write_file(playlist_t *playlist) { unsigned j; - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); rjsonwriter_add_spaces(writer, 6); rjsonwriter_add_string(writer, "subsystem_roms"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); - rjsonwriter_raw(writer, "[", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ": [\n", 4); for (j = 0; j < playlist->entries[i].subsystem_roms->size; j++) { @@ -1973,10 +1883,7 @@ void playlist_write_file(playlist_t *playlist) : ""); if (j < playlist->entries[i].subsystem_roms->size - 1) - { - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); - } + rjsonwriter_raw(writer, ",\n", 2); } rjsonwriter_raw(writer, "\n", 1); @@ -1996,10 +1903,7 @@ void playlist_write_file(playlist_t *playlist) } rjsonwriter_add_spaces(writer, 2); - rjsonwriter_raw(writer, "]", 1); - rjsonwriter_raw(writer, "\n", 1); - rjsonwriter_raw(writer, "}", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "]\n}\n", 4); if (!rjsonwriter_free(writer)) { diff --git a/runtime_file.c b/runtime_file.c index 5f67cc35bb..9cc9f2f7c7 100644 --- a/runtime_file.c +++ b/runtime_file.c @@ -1256,17 +1256,14 @@ void runtime_log_save(runtime_log_t *runtime_log) } /* Write output file */ - rjsonwriter_raw(writer, "{", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "{\n", 2); /* > Version entry */ rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "version"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, "1.0"); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); /* > Runtime entry */ snprintf(value_string, @@ -1277,11 +1274,9 @@ void runtime_log_save(runtime_log_t *runtime_log) rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "runtime"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, value_string); - rjsonwriter_raw(writer, ",", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, ",\n", 2); /* > Last played entry */ value_string[0] = '\0'; @@ -1294,14 +1289,12 @@ void runtime_log_save(runtime_log_t *runtime_log) rjsonwriter_add_spaces(writer, 2); rjsonwriter_add_string(writer, "last_played"); - rjsonwriter_raw(writer, ":", 1); - rjsonwriter_raw(writer, " ", 1); + rjsonwriter_raw(writer, ": ", 2); rjsonwriter_add_string(writer, value_string); rjsonwriter_raw(writer, "\n", 1); /* > Finalise */ - rjsonwriter_raw(writer, "}", 1); - rjsonwriter_raw(writer, "\n", 1); + rjsonwriter_raw(writer, "}\n", 2); /* Free JSON writer */ if (!rjsonwriter_free(writer)) diff --git a/tasks/task_translation.c b/tasks/task_translation.c index 646c58c882..be6b47ace9 100644 --- a/tasks/task_translation.c +++ b/tasks/task_translation.c @@ -968,45 +968,34 @@ bool run_translation_service(settings_t *settings, bool paused) if (!(jsonwriter = rjsonwriter_open_memory())) goto finish; - rjsonwriter_raw(jsonwriter, "{", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, "{ ", 2); rjsonwriter_add_string(jsonwriter, "image"); - rjsonwriter_raw(jsonwriter, ":", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, ": ", 2); rjsonwriter_add_string_len(jsonwriter, bmp64_buffer, bmp64_length); /* Form request... */ if (system_label) { - rjsonwriter_raw(jsonwriter, ",", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, ", ", 2); rjsonwriter_add_string(jsonwriter, "label"); - rjsonwriter_raw(jsonwriter, ":", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, ": ", 2); rjsonwriter_add_string(jsonwriter, system_label); } - rjsonwriter_raw(jsonwriter, ",", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, ", ", 2); rjsonwriter_add_string(jsonwriter, "state"); - rjsonwriter_raw(jsonwriter, ":", 1); - rjsonwriter_raw(jsonwriter, " ", 1); - rjsonwriter_raw(jsonwriter, "{", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, ": { ", 4); rjsonwriter_add_string(jsonwriter, "paused"); - rjsonwriter_raw(jsonwriter, ":", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, ": ", 2); rjsonwriter_rawf(jsonwriter, "%u", (paused ? 1 : 0)); { static const char* state_labels[] = { "b", "y", "select", "start", "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3" }; int i; for (i = 0; i < ARRAY_SIZE(state_labels); i++) { - rjsonwriter_raw(jsonwriter, ",", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, ", ", 2); rjsonwriter_add_string(jsonwriter, state_labels[i]); - rjsonwriter_raw(jsonwriter, ":", 1); - rjsonwriter_raw(jsonwriter, " ", 1); + rjsonwriter_raw(jsonwriter, ": ", 2); #ifdef HAVE_ACCESSIBILITY rjsonwriter_rawf(jsonwriter, "%u", (input_st->ai_gamepad_state[i] ? 1 : 0)); @@ -1015,10 +1004,7 @@ bool run_translation_service(settings_t *settings, bool paused) #endif } } - rjsonwriter_raw(jsonwriter, " ", 1); - rjsonwriter_raw(jsonwriter, "}", 1); - rjsonwriter_raw(jsonwriter, " ", 1); - rjsonwriter_raw(jsonwriter, "}", 1); + rjsonwriter_raw(jsonwriter, " } }", 4); if (!(json_buffer = rjsonwriter_get_memory_buffer(jsonwriter, NULL))) goto finish; /* ran out of memory */