Skip to content

Commit 2f6b5e2

Browse files
committed
chore: comments
1 parent 8af4396 commit 2f6b5e2

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/server/engine_shard.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ int32_t HuffmanCheckTask::Run(DbSlice* db_slice) {
151151
for (unsigned char c : val) {
152152
hist_[c]++;
153153
}
154+
155+
if (val.size() > 1024) {
156+
traverses_count = kMaxTraverses; // return early.
157+
string{}.swap(scratch_); // free memory.
158+
}
154159
}
155160
});
156161
traverses_count++;
@@ -721,19 +726,15 @@ void EngineShard::Heartbeat() {
721726
check_huffman = false; // trigger only once.
722727

723728
// launch the task
724-
HuffmanCheckTask* task = new HuffmanCheckTask();
725-
huffman_check_task_id_ = ProactorBase::me()->AddOnIdleTask([task] {
726-
if (!shard_ || !namespaces) {
727-
delete task;
728-
return -1;
729-
}
730-
731-
DbSlice& db_slice = namespaces->GetDefaultNamespace().GetDbSlice(shard_->shard_id());
732-
int32_t res = task->Run(&db_slice);
733-
if (res == -1)
734-
delete task;
735-
return res;
736-
});
729+
huffman_check_task_id_ =
730+
ProactorBase::me()->AddOnIdleTask([task = HuffmanCheckTask{}]() mutable {
731+
if (!shard_ || !namespaces) {
732+
return -1;
733+
}
734+
735+
DbSlice& db_slice = namespaces->GetDefaultNamespace().GetDbSlice(shard_->shard_id());
736+
return task.Run(&db_slice);
737+
});
737738
}
738739
}
739740
}

0 commit comments

Comments
 (0)