From 46ca83071e46222706601cdbcddf33b708d6a2de Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 16 May 2017 22:34:00 +0200 Subject: [PATCH 1/2] 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 --- ccutil/genericvector.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ccutil/genericvector.h b/ccutil/genericvector.h index 9ac95f11c1..4a2da79acf 100644 --- a/ccutil/genericvector.h +++ b/ccutil/genericvector.h @@ -364,10 +364,10 @@ typedef bool (*FileWriter)(const GenericVector& 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* 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); @@ -380,6 +380,12 @@ inline bool LoadDataFromFile(const STRING& filename, } return result; } + +inline bool LoadDataFromFile(const STRING& filename, + GenericVector* 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& data, From 0ba202f6edb80a95c4744805bd79a007cdab83a3 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 16 May 2017 22:58:10 +0200 Subject: [PATCH 2/2] Remove unneeded null pointer check Signed-off-by: Stefan Weil --- ccutil/genericvector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ccutil/genericvector.h b/ccutil/genericvector.h index 4a2da79acf..bdea83d221 100644 --- a/ccutil/genericvector.h +++ b/ccutil/genericvector.h @@ -676,7 +676,7 @@ void GenericVector::reserve(int size) { T* new_array = new T[size]; for (int i = 0; i < size_used_; ++i) new_array[i] = data_[i]; - if (data_ != NULL) delete[] data_; + delete[] data_; data_ = new_array; size_reserved_ = size; }