| 1045 | } |
| 1046 | |
| 1047 | void RowContainer::clear() { |
| 1048 | #ifndef NDEBUG |
| 1049 | LOG(INFO) << "RowContainer::clear, rows: " << numRows() |
| 1050 | << ", numFreeRows_: " << numFreeRows_ |
| 1051 | << ", string allocator size: " << stringAllocator_->size() |
| 1052 | << ", free space: " << stringAllocator_->freeSpace(); |
| 1053 | #endif |
| 1054 | const bool sharedStringAllocator = (stringAllocator_.use_count() != 1); |
| 1055 | if (checkFree_ || sharedStringAllocator || usesExternalMemory_) { |
| 1056 | constexpr int32_t kBatch = 1000; |
| 1057 | std::vector<char*> rows(kBatch); |
| 1058 | RowContainerIterator iter; |
| 1059 | while (auto numRows = listRows(&iter, kBatch, rows.data())) { |
| 1060 | eraseRows(folly::Range<char**>(rows.data(), numRows)); |
| 1061 | } |
| 1062 | } |
| 1063 | rows_.clear(); |
| 1064 | { |
| 1065 | std::vector<char*, StlAllocator<char*>> emptyRowPointers{ |
| 1066 | rowPointers_.get_allocator()}; |
| 1067 | rowPointers_.swap(emptyRowPointers); |
| 1068 | } |
| 1069 | if (!sharedStringAllocator) { |
| 1070 | if (checkFree_) { |
| 1071 | stringAllocator_->checkEmpty(); |
| 1072 | } |
| 1073 | stringAllocator_->clear(); |
| 1074 | } |
| 1075 | numRows_ = 0; |
| 1076 | numRowsWithNormalizedKey_ = 0; |
| 1077 | normalizedKeySize_ = originalNormalizedKeySize_; |
| 1078 | numFreeRows_ = 0; |
| 1079 | firstFreeRow_ = nullptr; |
| 1080 | } |