Skip to content

Commit

Permalink
osd,mon: switch from vectors_equal() to operator==()
Browse files Browse the repository at this point in the history
std::equal() in c++11 is able to compare elements of different container
types. but would be easier to read if we can just use the operator==().

Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Oct 1, 2017
1 parent 36f9607 commit d221aba
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2690,7 +2690,7 @@ bool OSDMonitor::preprocess_pgtemp(MonOpRequestRef op)
// an existing pg_primary field to imply a change
if (p->second.size() &&
(osdmap.pg_temp->count(p->first) == 0 ||
!vectors_equal(osdmap.pg_temp->get(p->first), p->second) ||
osdmap.pg_temp->get(p->first) != p->second ||
osdmap.primary_temp->count(p->first)))
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/osd/OSDMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ void OSDMap::clean_temps(CephContext *cct,
vector<int> raw_up;
int primary;
tmpmap.pg_to_raw_up(pg.first, &raw_up, &primary);
if (vectors_equal(raw_up, pg.second)) {
if (raw_up == pg.second) {
ldout(cct, 10) << __func__ << " removing pg_temp " << pg.first << " "
<< pg.second << " that matches raw_up mapping" << dendl;
if (osdmap.pg_temp->count(pg.first))
Expand Down Expand Up @@ -3712,7 +3712,7 @@ int OSDMap::clean_pg_upmaps(
vector<int> raw;
int primary;
pg_to_raw_osds(p.first, &raw, &primary);
if (vectors_equal(raw, p.second)) {
if (raw == p.second) {
ldout(cct, 10) << " removing redundant pg_upmap " << p.first << " "
<< p.second << dendl;
pending_inc->old_pg_upmap.insert(p.first);
Expand Down
12 changes: 0 additions & 12 deletions src/osd/OSDMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ class CephContext;
class CrushWrapper;
class health_check_map_t;

// FIXME C++11 does not have std::equal for two differently-typed containers.
// use this until we move to c++14
template<typename A, typename B>
bool vectors_equal(A a, B b)
{
return
a.size() == b.size() &&
(a.empty() ||
memcmp((char*)&a[0], (char*)&b[0], sizeof(a[0]) * a.size()) == 0);
}


/*
* we track up to two intervals during which the osd was alive and
* healthy. the most recent is [up_from,up_thru), where up_thru is
Expand Down

0 comments on commit d221aba

Please sign in to comment.