From 5ca3aee00ac3ac1a906de68c216907a7b41825fe Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 29 Jun 2017 11:20:38 +0200 Subject: FileUtil: Add a class for Exists/IsDirectory/GetSize Some code was calling more than one of these functions in a row (in particular, FileUtil.cpp itself did it a lot...), which is a waste since it's possible to call stat a single time and then read all three values from the stat struct. This commit adds a File::FileInfo class that calls stat once on construction and then lets Exists/IsDirectory/GetSize be executed very quickly. The performance improvement mostly matters for functions that can be handling a lot of files, such as File::ScanDirectoryTree. I've also done some cleanup in code that uses these functions. For instance, some code had checks like !Exists() || !IsDirectory(), which is functionally equivalent to !IsDirectory(), and some code was using File::GetSize even though there was an IOFile object that the code could call GetSize on. --- Source/Core/DiscIO/NANDContentLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/NANDContentLoader.cpp') diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp index 0178c3c14e..47ea26c81a 100644 --- a/Source/Core/DiscIO/NANDContentLoader.cpp +++ b/Source/Core/DiscIO/NANDContentLoader.cpp @@ -163,7 +163,7 @@ bool NANDContentLoader::Initialize(const std::string& name) return false; } - std::vector bytes(File::GetSize(tmd_filename)); + std::vector bytes(tmd_file.GetSize()); tmd_file.ReadBytes(bytes.data(), bytes.size()); m_tmd.SetBytes(std::move(bytes)); -- cgit v1.2.3