Skip to content

Commit 46ca830

Browse files
committed
genericvector: Add overloaded LoadDataFromFile
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 <[email protected]>
1 parent 852b678 commit 46ca830

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ccutil/genericvector.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ typedef bool (*FileWriter)(const GenericVector<char>& data,
364364
const STRING& filename);
365365
// The default FileReader loads the whole file into the vector of char,
366366
// returning false on error.
367-
inline bool LoadDataFromFile(const STRING& filename,
367+
inline bool LoadDataFromFile(const char *filename,
368368
GenericVector<char>* data) {
369369
bool result = false;
370-
FILE* fp = fopen(filename.string(), "rb");
370+
FILE* fp = fopen(filename, "rb");
371371
if (fp != NULL) {
372372
fseek(fp, 0, SEEK_END);
373373
size_t size = ftell(fp);
@@ -380,6 +380,12 @@ inline bool LoadDataFromFile(const STRING& filename,
380380
}
381381
return result;
382382
}
383+
384+
inline bool LoadDataFromFile(const STRING& filename,
385+
GenericVector<char>* data) {
386+
return LoadDataFromFile(filename.string(), data);
387+
}
388+
383389
// The default FileWriter writes the vector of char to the filename file,
384390
// returning false on error.
385391
inline bool SaveDataToFile(const GenericVector<char>& data,

0 commit comments

Comments
 (0)