Stop using thread local vectors

These don't build on macOS 10.9, and are unnecessary anyways.
Thread local variables should only be simple primitives.
This commit is contained in:
ridiculousfish 2021-08-10 12:59:56 -07:00
parent 7b55c0edb4
commit fdf8f17397
2 changed files with 15 additions and 13 deletions

View file

@ -360,9 +360,8 @@ wchar_t inputter_t::function_pop_arg() {
void inputter_t::function_push_args(readline_cmd_t code) { void inputter_t::function_push_args(readline_cmd_t code) {
int arity = input_function_arity(code); int arity = input_function_arity(code);
// Use a thread-local to prevent constant heap thrashing in the main input loop assert(event_storage_.empty() && "event_storage_ should be empty");
static FISH_THREAD_LOCAL std::vector<char_event_t> skipped; auto &skipped = event_storage_;
skipped.clear();
for (int i = 0; i < arity; i++) { for (int i = 0; i < arity; i++) {
// Skip and queue up any function codes. See issue #2357. // Skip and queue up any function codes. See issue #2357.
@ -380,6 +379,7 @@ void inputter_t::function_push_args(readline_cmd_t code) {
// Push the function codes back into the input stream. // Push the function codes back into the input stream.
this->insert_front(skipped.begin(), skipped.end()); this->insert_front(skipped.begin(), skipped.end());
event_storage_.clear();
} }
/// Perform the action of the specified binding. allow_commands controls whether fish commands /// Perform the action of the specified binding. allow_commands controls whether fish commands
@ -664,10 +664,8 @@ void inputter_t::mapping_execute_matching_or_generic(const command_handler_t &co
/// Helper function. Picks through the queue of incoming characters until we get to one that's not a /// Helper function. Picks through the queue of incoming characters until we get to one that's not a
/// readline function. /// readline function.
char_event_t inputter_t::read_characters_no_readline() { char_event_t inputter_t::read_characters_no_readline() {
// Use a thread-local vector to prevent repeated heap allocation, as this is called in the main assert(event_storage_.empty() && "saved_events_storage should be empty");
// input loop. auto &saved_events = event_storage_;
static FISH_THREAD_LOCAL std::vector<char_event_t> saved_events;
saved_events.clear();
char_event_t evt_to_return{0}; char_event_t evt_to_return{0};
for (;;) { for (;;) {
@ -682,6 +680,7 @@ char_event_t inputter_t::read_characters_no_readline() {
// Restore any readline functions // Restore any readline functions
this->insert_front(saved_events.cbegin(), saved_events.cend()); this->insert_front(saved_events.cbegin(), saved_events.cend());
event_storage_.clear();
return evt_to_return; return evt_to_return;
} }

View file

@ -60,18 +60,21 @@ class inputter_t final : private input_event_queue_t {
// Called when select() is interrupted by a signal. // Called when select() is interrupted by a signal.
void select_interrupted() override; void select_interrupted() override;
// We need a parser to evaluate bindings.
const std::shared_ptr<parser_t> parser_;
std::vector<wchar_t> input_function_args_{};
bool function_status_{false};
void function_push_arg(wchar_t arg); void function_push_arg(wchar_t arg);
void function_push_args(readline_cmd_t code); void function_push_args(readline_cmd_t code);
void mapping_execute(const input_mapping_t &m, const command_handler_t &command_handler); void mapping_execute(const input_mapping_t &m, const command_handler_t &command_handler);
void mapping_execute_matching_or_generic(const command_handler_t &command_handler); void mapping_execute_matching_or_generic(const command_handler_t &command_handler);
maybe_t<input_mapping_t> find_mapping(event_queue_peeker_t *peeker); maybe_t<input_mapping_t> find_mapping(event_queue_peeker_t *peeker);
char_event_t read_characters_no_readline(); char_event_t read_characters_no_readline();
// We need a parser to evaluate bindings.
const std::shared_ptr<parser_t> parser_;
std::vector<wchar_t> input_function_args_{};
bool function_status_{false};
// Transient storage to avoid repeated allocations.
std::vector<char_event_t> event_storage_{};
}; };
struct input_mapping_name_t { struct input_mapping_name_t {