From b6337900af763ebd301eabcddffb8220cbd5898f Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Thu, 26 Dec 2013 17:25:17 +0100 Subject: [PATCH] Optimize read to only read the hierarchy once --- kernel/src/fat32.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/kernel/src/fat32.cpp b/kernel/src/fat32.cpp index 4a41e258..063bf284 100644 --- a/kernel/src/fat32.cpp +++ b/kernel/src/fat32.cpp @@ -495,6 +495,8 @@ std::string fat32::read_file(dd disk, const disks::partition_descriptor& partiti return {}; } + uint32_t cluster_number; + size_t file_size = 0; auto found = false; auto all_files = files(disk, path); @@ -502,6 +504,7 @@ std::string fat32::read_file(dd disk, const disks::partition_descriptor& partiti if(f.file_name == file){ found = true; file_size = f.size; + cluster_number = f.location; break; } } @@ -510,20 +513,6 @@ std::string fat32::read_file(dd disk, const disks::partition_descriptor& partiti return {}; } - std::vector complete_path; - for(auto& p : path){ - complete_path.push_back(p); - } - complete_path.push_back(file); - - auto cluster_number_search = find_cluster_number(disk, complete_path); - - if(!cluster_number_search.first){ - return {}; - } - - auto cluster_number = cluster_number_search.second; - std::string content(file_size + 1); size_t read = 0;