Repository: mesos Updated Branches: refs/heads/master 8f378c6b7 -> 2685f1488
Updated metrics add / remove to avoid double lookups. When adding / removing metrics, we were performing double lookups on the metrics map. Removing these provides a slight performance improvement. Review: https://reviews.apache.org/r/67890 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2685f148 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2685f148 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2685f148 Branch: refs/heads/master Commit: 2685f148896667f9a77e5e3d2f01d92ec8963609 Parents: 54a8443 Author: Benjamin Mahler <[email protected]> Authored: Wed Jul 11 15:49:15 2018 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Wed Jul 25 14:13:51 2018 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/src/metrics/metrics.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/2685f148/3rdparty/libprocess/src/metrics/metrics.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/metrics/metrics.cpp b/3rdparty/libprocess/src/metrics/metrics.cpp index e2fdbc7..ba1962f 100644 --- a/3rdparty/libprocess/src/metrics/metrics.cpp +++ b/3rdparty/libprocess/src/metrics/metrics.cpp @@ -120,23 +120,24 @@ string MetricsProcess::help() Future<Nothing> MetricsProcess::add(Owned<Metric> metric) { - if (metrics.count(metric->name()) > 0) { + bool inserted = metrics.emplace(metric->name(), metric).second; + + if (!inserted) { return Failure("Metric '" + metric->name() + "' was already added"); } - metrics[metric->name()] = metric; return Nothing(); } Future<Nothing> MetricsProcess::remove(const string& name) { - if (metrics.count(name) == 0) { + size_t erased = metrics.erase(name); + + if (erased == 0) { return Failure("Metric '" + name + "' not found"); } - metrics.erase(name); - return Nothing(); }
