Skip to content

Commit

Permalink
genericvector: Add overloaded LoadDataFromFile
Browse files Browse the repository at this point in the history
Several code locations call that method with a normal C string,
so overload it to accept that without a conversion to a STRING
object. This saves unneeded new / memcpy / delete operations.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed May 16, 2017
1 parent 852b678 commit 46ca830
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ccutil/genericvector.h
Expand Up @@ -364,10 +364,10 @@ typedef bool (*FileWriter)(const GenericVector<char>& data,
const STRING& filename);
// The default FileReader loads the whole file into the vector of char,
// returning false on error.
inline bool LoadDataFromFile(const STRING& filename,
inline bool LoadDataFromFile(const char *filename,
GenericVector<char>* data) {
bool result = false;
FILE* fp = fopen(filename.string(), "rb");
FILE* fp = fopen(filename, "rb");
if (fp != NULL) {
fseek(fp, 0, SEEK_END);
size_t size = ftell(fp);
Expand All @@ -380,6 +380,12 @@ inline bool LoadDataFromFile(const STRING& filename,
}
return result;
}

inline bool LoadDataFromFile(const STRING& filename,
GenericVector<char>* data) {
return LoadDataFromFile(filename.string(), data);
}

// The default FileWriter writes the vector of char to the filename file,
// returning false on error.
inline bool SaveDataToFile(const GenericVector<char>& data,
Expand Down

0 comments on commit 46ca830

Please sign in to comment.