From df2d4f3dd9fa5c0250ec4d8747f37c2c977c14d0 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Wed, 27 Dec 2023 21:58:50 +0300 Subject: [PATCH] reverse-ramdisk.c: reorder operations to improve speed --- c-programming/reverse-ramdisk.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/c-programming/reverse-ramdisk.c b/c-programming/reverse-ramdisk.c index da14f2a..56ec4ce 100644 --- a/c-programming/reverse-ramdisk.c +++ b/c-programming/reverse-ramdisk.c @@ -81,12 +81,14 @@ int tf_alloc(size_t n, size_t type_size) { return -1; } - // Assign the ID and file path + // Assign the ID, file path, file handler temp_file->ID = num_temp_files; temp_file->file_path = strdup(file_path); temp_file->file = file; - // Increase the number of temp files + // Add the temp file to the array + temp_files[num_temp_files] = *temp_file; + num_temp_files++; // Allocate/reallocate memory for the temp_files structure @@ -100,9 +102,6 @@ int tf_alloc(size_t n, size_t type_size) { return -1; } - // Add the temp file to the array - temp_files[num_temp_files - 1] = *temp_file; - return temp_file->ID; }