From 0c7aab1556e1e2a9186787fd251c23245e993a8f Mon Sep 17 00:00:00 2001 From: Heather Anderson Date: Sun, 2 Aug 2020 14:38:55 -0700 Subject: [PATCH] minor code review --- .../ui/src/ui/types/ContextAwareProfile.cpp | 40 +++++++++---------- .../ui/src/ui/types/ContextAwareProfile.h | 15 +++---- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/libraries/ui/src/ui/types/ContextAwareProfile.cpp b/libraries/ui/src/ui/types/ContextAwareProfile.cpp index 5df2d34dfa..ee823ec784 100644 --- a/libraries/ui/src/ui/types/ContextAwareProfile.cpp +++ b/libraries/ui/src/ui/types/ContextAwareProfile.cpp @@ -22,19 +22,19 @@ static const QString RESTRICTED_FLAG_PROPERTY = "RestrictFileAccess"; -QReadWriteLock ContextAwareProfile::gl_contextMapProtect; -ContextAwareProfile::ContextMap ContextAwareProfile::gl_contextMap; +QReadWriteLock ContextAwareProfile::_global_contextMapProtect; +ContextAwareProfile::ContextMap ContextAwareProfile::_global_contextMap; ContextAwareProfile::ContextAwareProfile(QQmlContext* context) : ContextAwareProfileParent(context), _context(context) { assert(context); { // register our object for future updates - QWriteLocker guard(&gl_contextMapProtect); - ContextMap::iterator setLookup = gl_contextMap.find(_context); - if (setLookup == gl_contextMap.end()) { - setLookup = gl_contextMap.insert(_context, ContextAwareProfileSet()); + QWriteLocker guard(&_global_contextMapProtect); + ContextMap::iterator setLookup = _global_contextMap.find(_context); + if (setLookup == _global_contextMap.end()) { + setLookup = _global_contextMap.insert(_context, ContextAwareProfileSet()); } - assert(setLookup != gl_contextMap.end()); + assert(setLookup != _global_contextMap.end()); ContextAwareProfileSet& profileSet = setLookup.value(); assert(profileSet.find(this) == profileSet.end()); profileSet.insert(this); @@ -45,15 +45,15 @@ ContextAwareProfile::ContextAwareProfile(QQmlContext* context) : ContextAwarePro ContextAwareProfile::~ContextAwareProfile() { { // deregister our object - QWriteLocker guard(&gl_contextMapProtect); - ContextMap::iterator setLookup = gl_contextMap.find(_context); - assert(setLookup != gl_contextMap.end()); - if (setLookup != gl_contextMap.end()) { + QWriteLocker guard(&_global_contextMapProtect); + ContextMap::iterator setLookup = _global_contextMap.find(_context); + assert(setLookup != _global_contextMap.end()); + if (setLookup != _global_contextMap.end()) { ContextAwareProfileSet& profileSet = setLookup.value(); assert(profileSet.find(this) != profileSet.end()); profileSet.remove(this); if (profileSet.isEmpty()) { - gl_contextMap.erase(setLookup); + _global_contextMap.erase(setLookup); } } } @@ -65,15 +65,13 @@ void ContextAwareProfile::restrictContext(QQmlContext* context, bool restrict) { context->setContextProperty(RESTRICTED_FLAG_PROPERTY, restrict); // broadcast the new value to any registered ContextAwareProfile objects - { // deregister our object - QReadLocker guard(&gl_contextMapProtect); - ContextMap::const_iterator setLookup = gl_contextMap.find(context); - if (setLookup != gl_contextMap.end()) { - const ContextAwareProfileSet& profileSet = setLookup.value(); - for (ContextAwareProfileSet::const_iterator profileIterator = profileSet.begin(); - profileIterator != profileSet.end(); profileIterator++) { - (*profileIterator)->onIsRestrictedChanged(restrict); - } + QReadLocker guard(&_global_contextMapProtect); + ContextMap::const_iterator setLookup = _global_contextMap.find(context); + if (setLookup != _global_contextMap.end()) { + const ContextAwareProfileSet& profileSet = setLookup.value(); + for (ContextAwareProfileSet::const_iterator profileIterator = profileSet.begin(); + profileIterator != profileSet.end(); profileIterator++) { + (*profileIterator)->onIsRestrictedChanged(restrict); } } } diff --git a/libraries/ui/src/ui/types/ContextAwareProfile.h b/libraries/ui/src/ui/types/ContextAwareProfile.h index d8ec762858..c6f3020c4f 100644 --- a/libraries/ui/src/ui/types/ContextAwareProfile.h +++ b/libraries/ui/src/ui/types/ContextAwareProfile.h @@ -12,7 +12,7 @@ #define hifi_ContextAwareProfile_h #include -#include +#include #include #include #include @@ -50,17 +50,18 @@ protected: ContextAwareProfile(QQmlContext* parent); ~ContextAwareProfile(); - void onIsRestrictedChanged(bool newValue); + +private: + typedef QSet ContextAwareProfileSet; + typedef QHash ContextMap; QQmlContext* _context{ nullptr }; std::atomic _isRestricted{ false }; -private: - typedef QSet ContextAwareProfileSet; - typedef QMap ContextMap; + static QReadWriteLock _global_contextMapProtect; + static ContextMap _global_contextMap; - static QReadWriteLock gl_contextMapProtect; - static ContextMap gl_contextMap; + void onIsRestrictedChanged(bool newValue); }; #endif // hifi_FileTypeProfile_h