Commit 542d5e85 authored by Guolin Ke's avatar Guolin Ke Committed by GitHub
Browse files

clean code

parent 623ac048
...@@ -25,20 +25,8 @@ public: ...@@ -25,20 +25,8 @@ public:
* \brief Destructor * \brief Destructor
*/ */
~LRUPool() { ~LRUPool() {
if (pool_ != nullptr) { FreeAll();
delete[] pool_;
}
if (mapper_ != nullptr) {
delete[] mapper_;
}
if (inverse_mapper_ != nullptr) {
delete[] inverse_mapper_;
}
if (last_used_time_ != nullptr) {
delete[] last_used_time_;
}
} }
/*! /*!
* \brief Reset pool size * \brief Reset pool size
* \param cache_size Max cache size * \param cache_size Max cache size
...@@ -46,19 +34,7 @@ public: ...@@ -46,19 +34,7 @@ public:
*/ */
void ResetSize(int cache_size, int total_size) { void ResetSize(int cache_size, int total_size) {
// free old memory // free old memory
if (pool_ != nullptr) { FreeAll();
delete[] pool_;
}
if (mapper_ != nullptr) {
delete[] mapper_;
}
if (inverse_mapper_ != nullptr) {
delete[] inverse_mapper_;
}
if (last_used_time_ != nullptr) {
delete[] last_used_time_;
}
cache_size_ = cache_size; cache_size_ = cache_size;
// at least need 2 bucket to store smaller leaf and larger leaf // at least need 2 bucket to store smaller leaf and larger leaf
CHECK(cache_size_ >= 2); CHECK(cache_size_ >= 2);
...@@ -146,6 +122,20 @@ public: ...@@ -146,6 +122,20 @@ public:
inverse_mapper_[slot] = dst_idx; inverse_mapper_[slot] = dst_idx;
} }
private: private:
void FreeAll(){
if (pool_ != nullptr) {
delete[] pool_;
}
if (mapper_ != nullptr) {
delete[] mapper_;
}
if (inverse_mapper_ != nullptr) {
delete[] inverse_mapper_;
}
if (last_used_time_ != nullptr) {
delete[] last_used_time_;
}
}
T* pool_ = nullptr; T* pool_ = nullptr;
int cache_size_; int cache_size_;
int total_size_; int total_size_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment