The main reason for this PR was to get rid of the expensive deep copies of strings passing by value. (I just started with this module, as it is the shortest. I will update the others as well.)
Additionally I refactored the module a bit.
Following are the main changes:
Pass string by const reference
Pass WebServer by reference, not by pointer (this not a performance improvement, but by using references we do not have to take care for nullptr.)
Add the file system object as reference instead of using the global instance (keyword: dependency injection).
Added the FileGuard class, which automatically closes a file when going out of scope by using the RAII (Resource acquisition is initialization) idiom. At least, the fs::File class takes already care to close the file, when the last copy of the file handle is deleted. With the FileGuard you have more control, when file use in a local scope is close without calling the close() method manually. Additionally it provides a method to verify if the file was opened successfully.
The main reason for this PR was to get rid of the expensive deep copies of strings passing by value. (I just started with this module, as it is the shortest. I will update the others as well.) Additionally I refactored the module a bit. Following are the main changes:
fs::File
class takes already care to close the file, when the last copy of the file handle is deleted. With theFileGuard
you have more control, when file use in a local scope is close without calling theclose()
method manually. Additionally it provides a method to verify if the file was opened successfully.