From a02a60c6580572f1e2945b3ebccb7c1eabfc40f8 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 19 Sep 2018 10:46:24 -0700 Subject: [PATCH] Field::m_hash friends Avoid additional access of m_hash by FieldCreate::Helper which has an unclear (though I think correct) friend relationship with Field. Attempt to placate old gcc 3.4.4 --- src/factory/FieldCreateFactory.cpp | 12 +++++++----- src/pv/pvIntrospect.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/factory/FieldCreateFactory.cpp b/src/factory/FieldCreateFactory.cpp index e0866e7..b5e3d46 100644 --- a/src/factory/FieldCreateFactory.cpp +++ b/src/factory/FieldCreateFactory.cpp @@ -38,24 +38,26 @@ size_t Field::num_instances; struct Field::Helper { - static void hash(Field *fld) { + static unsigned hash(Field *fld) { std::ostringstream key; // hash the output of operator<<() // not efficient, but stable within this process. key<<(*fld); - fld->m_hash = epicsStrHash(key.str().c_str(), 0xbadc0de1); + unsigned H = epicsStrHash(key.str().c_str(), 0xbadc0de1); + fld->m_hash = H; + return H; } }; struct FieldCreate::Helper { template static void cache(const FieldCreate *create, std::tr1::shared_ptr& ent) { - Field::Helper::hash(ent.get()); + unsigned hash = Field::Helper::hash(ent.get()); Lock G(create->mutex); // we examine raw pointers stored in create->cache, which is safe under create->mutex - std::pair itp(create->cache.equal_range(ent->m_hash)); + std::pair itp(create->cache.equal_range(hash)); for(; itp.first!=itp.second; ++itp.first) { Field* cent(itp.first->second); FLD* centx(dynamic_cast(cent)); @@ -72,7 +74,7 @@ struct FieldCreate::Helper { } } - create->cache.insert(std::make_pair(ent->m_hash, ent.get())); + create->cache.insert(std::make_pair(hash, ent.get())); // cache cleaned from Field::~Field } }; diff --git a/src/pv/pvIntrospect.h b/src/pv/pvIntrospect.h index 9ebed70..9458571 100644 --- a/src/pv/pvIntrospect.h +++ b/src/pv/pvIntrospect.h @@ -351,6 +351,7 @@ private: const Type m_fieldType; unsigned int m_hash; struct Helper; + friend struct Helper; friend class StructureArray; friend class Structure;