mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 16:19:14 +08:00
Remove reader_test_should_cancel
Use cancel_checker more pervasively.
This commit is contained in:
parent
0f7bba5f0e
commit
1978ac87a1
|
@ -249,7 +249,8 @@ int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||
switch (opts.hist_cmd) {
|
||||
case HIST_SEARCH: {
|
||||
if (!history->search(opts.search_type, args, opts.show_time_format, opts.max_items,
|
||||
opts.case_sensitive, opts.null_terminate, opts.reverse, streams)) {
|
||||
opts.case_sensitive, opts.null_terminate, opts.reverse,
|
||||
parser.cancel_checker(), streams)) {
|
||||
status = STATUS_CMD_ERROR;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1347,7 +1347,7 @@ static void walk_wrap_chain_recursive(const wcstring &command_line, source_range
|
|||
wrap_chain_visited_set_t *visited, size_t depth) {
|
||||
// Limit our recursion depth. This prevents cycles in the wrap chain graph from overflowing.
|
||||
if (depth > 24) return;
|
||||
if (reader_test_should_cancel()) return;
|
||||
if (cancel_checker()) return;
|
||||
|
||||
// Extract command from the command line and invoke the receiver with it.
|
||||
wcstring command(command_line, command_range.start, command_range.length);
|
||||
|
|
|
@ -605,10 +605,6 @@ bool history_search_t::go_backwards() {
|
|||
|
||||
size_t index = current_index_;
|
||||
while (++index < max_index) {
|
||||
if (reader_test_should_cancel()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
history_item_t item = history_->item_at_index(index);
|
||||
|
||||
// We're done if it's empty or we cancelled.
|
||||
|
@ -1344,10 +1340,11 @@ void history_t::save() { impl()->save(); }
|
|||
/// \p func returns true, continue the search; else stop it.
|
||||
static void do_1_history_search(history_t &hist, history_search_type_t search_type,
|
||||
const wcstring &search_string, bool case_sensitive,
|
||||
const std::function<bool(const history_item_t &item)> &func) {
|
||||
const std::function<bool(const history_item_t &item)> &func,
|
||||
const cancel_checker_t &cancel_check) {
|
||||
history_search_t searcher = history_search_t(hist, search_string, search_type,
|
||||
case_sensitive ? 0 : history_search_ignore_case);
|
||||
while (searcher.go_backwards()) {
|
||||
while (!cancel_check() && searcher.go_backwards()) {
|
||||
if (!func(searcher.current_item())) {
|
||||
break;
|
||||
}
|
||||
|
@ -1357,7 +1354,8 @@ static void do_1_history_search(history_t &hist, history_search_type_t search_ty
|
|||
// Searches history.
|
||||
bool history_t::search(history_search_type_t search_type, const wcstring_list_t &search_args,
|
||||
const wchar_t *show_time_format, size_t max_items, bool case_sensitive,
|
||||
bool null_terminate, bool reverse, io_streams_t &streams) {
|
||||
bool null_terminate, bool reverse, const cancel_checker_t &cancel_check,
|
||||
io_streams_t &streams) {
|
||||
wcstring_list_t collected;
|
||||
wcstring formatted_record;
|
||||
size_t remaining = max_items;
|
||||
|
@ -1379,14 +1377,16 @@ bool history_t::search(history_search_type_t search_type, const wcstring_list_t
|
|||
|
||||
if (search_args.empty()) {
|
||||
// The user had no search terms; just append everything.
|
||||
do_1_history_search(*this, history_search_type_t::match_everything, {}, false, func);
|
||||
do_1_history_search(*this, history_search_type_t::match_everything, {}, false, func,
|
||||
cancel_check);
|
||||
} else {
|
||||
for (const wcstring &search_string : search_args) {
|
||||
if (search_string.empty()) {
|
||||
streams.err.append_format(L"Searching for the empty string isn't allowed");
|
||||
return false;
|
||||
}
|
||||
do_1_history_search(*this, search_type, search_string, case_sensitive, func);
|
||||
do_1_history_search(*this, search_type, search_string, case_sensitive, func,
|
||||
cancel_check);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -172,7 +172,8 @@ class history_t {
|
|||
// Searches history.
|
||||
bool search(history_search_type_t search_type, const wcstring_list_t &search_args,
|
||||
const wchar_t *show_time_format, size_t max_items, bool case_sensitive,
|
||||
bool null_terminate, bool reverse, io_streams_t &streams);
|
||||
bool null_terminate, bool reverse, const cancel_checker_t &cancel_check,
|
||||
io_streams_t &streams);
|
||||
|
||||
// Irreversibly clears history.
|
||||
void clear();
|
||||
|
|
|
@ -127,10 +127,6 @@ enum class jump_precision_t { till, to };
|
|||
/// background threads to notice it and skip doing work that they would otherwise have to do.
|
||||
static std::atomic<unsigned> s_generation;
|
||||
|
||||
/// This pthreads generation count is set when an autosuggestion background thread starts up, so it
|
||||
/// can easily check if the work it is doing is no longer useful.
|
||||
static thread_local unsigned s_thread_generation;
|
||||
|
||||
/// Helper to get the generation count
|
||||
static inline unsigned read_generation_count() {
|
||||
return s_generation.load(std::memory_order_relaxed);
|
||||
|
@ -853,14 +849,6 @@ void reader_data_t::repaint_if_needed() {
|
|||
|
||||
void reader_reset_interrupted() { interrupted = 0; }
|
||||
|
||||
bool reader_test_should_cancel() {
|
||||
if (is_main_thread()) {
|
||||
return interrupted;
|
||||
} else {
|
||||
return read_generation_count() != s_thread_generation;
|
||||
}
|
||||
}
|
||||
|
||||
int reader_test_and_clear_interrupted() {
|
||||
int res = interrupted;
|
||||
if (res) {
|
||||
|
@ -1300,7 +1288,6 @@ static std::function<autosuggestion_result_t(void)> get_autosuggestion_performer
|
|||
if (ctx.check_cancel()) {
|
||||
return nothing;
|
||||
}
|
||||
s_thread_generation = generation_count;
|
||||
|
||||
// Let's make sure we aren't using the empty string.
|
||||
if (search_string.empty()) {
|
||||
|
|
|
@ -117,11 +117,6 @@ size_t reader_get_cursor_pos();
|
|||
/// selection, true otherwise.
|
||||
bool reader_get_selection(size_t *start, size_t *len);
|
||||
|
||||
/// Return whether we have been interrupted and should cancel the current operation.
|
||||
/// This may be because we received a sigint, or because we are in a background thread
|
||||
/// and the job is now stale.
|
||||
bool reader_test_should_cancel();
|
||||
|
||||
/// Return the value of the interrupted flag, which is set by the sigint handler, and clear it if it
|
||||
/// was set. In practice this will return 0 or SIGINT.
|
||||
int reader_test_and_clear_interrupted();
|
||||
|
|
Loading…
Reference in New Issue
Block a user