diff options
| author | Joel Klinghed <the_jk@opera.com> | 2026-05-29 11:22:59 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@opera.com> | 2026-05-29 11:22:59 +0200 |
| commit | a6ac90c83edbade279cccfdb6d8ca02d8e5a60b8 (patch) | |
| tree | 02812431b6aa823863fd393439688fdcd1a4d76a /src/fake_monitor.cc | |
| parent | 9d1bbc93bb4a49ae73ae39ef323e2e18f303f0d9 (diff) | |
Use more effective lookup
Diffstat (limited to 'src/fake_monitor.cc')
| -rw-r--r-- | src/fake_monitor.cc | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/src/fake_monitor.cc b/src/fake_monitor.cc index 336ad9c..be775e1 100644 --- a/src/fake_monitor.cc +++ b/src/fake_monitor.cc @@ -46,26 +46,6 @@ public: return machines_.size(); } - uint32_t id(size_t index) const override { - auto it = machines_.begin(); - while (index--) ++it; - if (it == machines_.end()) { - assert(false); - return static_cast<uint32_t>(-1); - } - return it->first; - } - - Machine machine_at(size_t index) const override { - auto it = machines_.begin(); - while (index--) ++it; - if (it == machines_.end()) { - assert(false); - return Machine(); - } - return it->second.data; - } - Machine machine(uint32_t id) const override { auto it = machines_.find(id); if (it == machines_.end()) { @@ -193,6 +173,12 @@ private: } } + uint32_t id_at(size_t index) const { + auto it = machines_.begin(); + while (index--) ++it; + return it->first; + } + void fiddle_jobs(Looper*, uint32_t) { timer_ = 0; @@ -208,11 +194,11 @@ private: auto host = rand() % machines_.size(); auto target = rand() % machines_.size(); do { - auto tgtid = this->id(target); + auto tgtid = id_at(target); auto& entry = machines_[tgtid]; if (entry.active < entry.data.max_jobs) { entry.active++; - add_job(id, host != target ? this->id(host) : tgtid, tgtid); + add_job(id, host != target ? id_at(host) : tgtid, tgtid); break; } target = rand() % machines_.size(); |
