Short-circuit --head handler when count is reached
This commit is contained in:
parent
3e21a171c7
commit
2f9ea39869
2 changed files with 11 additions and 4 deletions
|
|
@ -107,6 +107,9 @@ void truncate_xacts::flush()
|
||||||
|
|
||||||
void truncate_xacts::operator()(post_t& post)
|
void truncate_xacts::operator()(post_t& post)
|
||||||
{
|
{
|
||||||
|
if (completed)
|
||||||
|
return;
|
||||||
|
|
||||||
if (last_xact != post.xact) {
|
if (last_xact != post.xact) {
|
||||||
if (last_xact)
|
if (last_xact)
|
||||||
xacts_seen++;
|
xacts_seen++;
|
||||||
|
|
@ -114,8 +117,11 @@ void truncate_xacts::operator()(post_t& post)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tail_count == 0 && head_count > 0 &&
|
if (tail_count == 0 && head_count > 0 &&
|
||||||
static_cast<int>(xacts_seen) >= head_count)
|
static_cast<int>(xacts_seen) >= head_count) {
|
||||||
|
flush();
|
||||||
|
completed = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
posts.push_back(&post);
|
posts.push_back(&post);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,8 +125,9 @@ public:
|
||||||
|
|
||||||
class truncate_xacts : public item_handler<post_t>
|
class truncate_xacts : public item_handler<post_t>
|
||||||
{
|
{
|
||||||
int head_count;
|
int head_count;
|
||||||
int tail_count;
|
int tail_count;
|
||||||
|
bool completed;
|
||||||
|
|
||||||
posts_list posts;
|
posts_list posts;
|
||||||
std::size_t xacts_seen;
|
std::size_t xacts_seen;
|
||||||
|
|
@ -139,7 +140,7 @@ public:
|
||||||
int _head_count, int _tail_count)
|
int _head_count, int _tail_count)
|
||||||
: item_handler<post_t>(handler),
|
: item_handler<post_t>(handler),
|
||||||
head_count(_head_count), tail_count(_tail_count),
|
head_count(_head_count), tail_count(_tail_count),
|
||||||
xacts_seen(0), last_xact(NULL) {
|
completed(false), xacts_seen(0), last_xact(NULL) {
|
||||||
TRACE_CTOR(truncate_xacts, "post_handler_ptr, int, int");
|
TRACE_CTOR(truncate_xacts, "post_handler_ptr, int, int");
|
||||||
}
|
}
|
||||||
virtual ~truncate_xacts() {
|
virtual ~truncate_xacts() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue