Convert job list to a dequeue

We never insert elements into the middle of a job list, only move
elements to the top. While that can be done "efficiently" with a list, it
can be done faster with a deque, which also won't thrash the cache when
enumerating over jobs.

This speeds up enumeration in the critical path in
`process_mark_finished_children()`.
This commit is contained in:
Mahmoud Al-Qudsi 2018-10-12 19:45:49 -05:00
parent d467bb58d9
commit 54050bd4c5
2 changed files with 3 additions and 3 deletions

View file

@ -591,7 +591,7 @@ void parser_t::job_promote(job_t *job) {
assert(loc != my_job_list.end());
// Move the job to the beginning.
my_job_list.splice(my_job_list.begin(), my_job_list, loc);
std::rotate(my_job_list.begin(), loc, my_job_list.end());
}
job_t *parser_t::job_get(job_id_t id) {

View file

@ -11,7 +11,7 @@
#include <termios.h>
#include <unistd.h>
#include <list>
#include <deque>
#include <memory>
#include <vector>
@ -243,7 +243,7 @@ extern bool is_login;
extern int is_event;
// List of jobs. We sometimes mutate this while iterating - hence it must be a list, not a vector
typedef std::list<shared_ptr<job_t>> job_list_t;
typedef std::deque<shared_ptr<job_t>> job_list_t;
bool job_list_is_empty(void);