Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genericvector: Small optimizations #925

Merged
merged 2 commits into from
May 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ccutil/genericvector.h
Original file line number Diff line number Diff line change
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 Expand Up @@ -670,7 +676,7 @@ void GenericVector<T>::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;
}
Expand Down