[search] try to fix an issue with search progress bar never stopping

Possible fix for #588
This commit is contained in:
Timothy Stack 2019-01-26 08:01:44 -08:00
parent 0c2f84a3c0
commit 69508e6467
4 changed files with 22 additions and 20 deletions

View File

@ -155,4 +155,4 @@ while True:
for i in range(random.randrange(0, 4)):
with open(fname, "a+") as fp:
fp.write(gen.next())
time.sleep(random.uniform(0.25, 0.75))
time.sleep(random.uniform(0.00, 0.001))

View File

@ -63,8 +63,7 @@ grep_proc<LineType>::grep_proc(pcre *code, grep_proc_source<LineType> &gps)
template<typename LineType>
grep_proc<LineType>::~grep_proc()
{
this->gp_queue.clear();
this->cleanup();
this->invalidate();
}
template<typename LineType>
@ -274,13 +273,9 @@ void grep_proc<LineType>::dispatch_line(char *line)
{
int start, end, capture_start;
require(line != NULL);
require(line != nullptr);
if (sscanf(line, "h%d", this->gp_highest_line.out()) == 1) {
if (this->gp_sink) {
this->gp_sink->grep_end(*this);
}
this->gp_child_queue_size -= 1;
} else if (sscanf(line, "%d", this->gp_last_line.out()) == 1) {
/* Starting a new line with matches. */
ensure(this->gp_last_line >= 0);
@ -290,7 +285,7 @@ void grep_proc<LineType>::dispatch_line(char *line)
require(end >= 0);
/* Pass the match offsets to the sink delegate. */
if (this->gp_sink != NULL) {
if (this->gp_sink != nullptr) {
this->gp_sink->grep_match(*this, this->gp_last_line, start, end);
}
}
@ -299,17 +294,17 @@ void grep_proc<LineType>::dispatch_line(char *line)
require(end >= 0);
/* Pass the captured strings to the sink delegate. */
if (this->gp_sink != NULL) {
if (this->gp_sink != nullptr) {
this->gp_sink->grep_capture(*this,
this->gp_last_line,
start,
end,
start < 0 ?
NULL : &line[capture_start]);
nullptr : &line[capture_start]);
}
}
else if (line[0] == '/') {
if (this->gp_sink != NULL) {
if (this->gp_sink != nullptr) {
this->gp_sink->grep_match_end(*this, this->gp_last_line);
}
}
@ -380,4 +375,17 @@ void grep_proc<LineType>::check_poll_set(const std::vector<struct pollfd> &pollf
ensure(this->invariant());
}
template<typename LineType>
grep_proc<LineType> &grep_proc<LineType>::invalidate()
{
if (this->gp_sink) {
for (int lpc = 0; lpc < this->gp_queue.size(); lpc++) {
this->gp_sink->grep_end(*this);
}
}
this->gp_queue.clear();
this->cleanup();
return *this;
}
template class grep_proc<vis_line_t>;

View File

@ -196,10 +196,7 @@ public:
this->gp_sink = gpd;
};
grep_proc &invalidate() {
this->cleanup();
return *this;
};
grep_proc &invalidate();
/** @param gpd The sink to send results to. */
void set_control(grep_proc_control *gpc)

View File

@ -385,11 +385,8 @@ void textview_curses::execute_search(const std::string &regex_orig)
this->match_reset();
if (regex.empty() && this->tc_search_child != nullptr) {
this->grep_begin(*(this->tc_search_child->get_grep_proc()), 0_vl, -1_vl);
this->grep_end(*(this->tc_search_child->get_grep_proc()));
}
this->tc_search_child.reset();
this->tc_source_search_child.reset();
log_debug("start search for: '%s'", regex.c_str());