activesync: code cleanup (cppcheck)

cppcheck complains about sub-optimal performance (std::string should be passed
via const reference, not by value). It is not critical here, but for the sake
of getting clean scan results let's fix the issues...

One of the offending methods was never implemented, nor called. Removed.

The Collection class did not initialize all its members. Even if the code
never relied on them being initialized (not checked), it is better to be
safe and predictable, which means initializing all members in the constructor.
This commit is contained in:
Patrick Ohly 2014-01-07 00:03:08 -08:00
parent a0de6e6720
commit 4e833ec546
2 changed files with 21 additions and 9 deletions

View File

@ -69,7 +69,7 @@ std::string ActiveSyncSource::Collection::fullPath() {
return pathName;
}
void ActiveSyncSource::findCollections(const std::string account, const bool force_update)
void ActiveSyncSource::findCollections(const std::string &account, const bool force_update)
{
GErrorCXX gerror;
EasSyncHandlerCXX handler;
@ -179,15 +179,23 @@ ActiveSyncSource::Databases ActiveSyncSource::getDatabases()
return result;
}
std::string ActiveSyncSource::lookupFolder(std::string folder) {
std::string ActiveSyncSource::lookupFolder(const std::string &folder) {
// If folder matches a collectionId, use that
if (m_collections.find(folder) != m_collections.end()) return folder;
// If folder begins with /, drop it
if (folder[0] == '/') folder.erase(0,1);
std::string key;
if (!folder.empty() && folder[0] == '/') {
key = folder.substr(1);
} else {
key = folder;
}
// Lookup folder name
if (m_folderPaths.find(folder) != m_folderPaths.end()) return m_folderPaths[folder];
FolderPaths::const_iterator entry = m_folderPaths.find(key);
if (entry != m_folderPaths.end()) {
return entry->second;
}
// Not found
return "";

View File

@ -180,9 +180,8 @@ class ActiveSyncSource :
void setStartSyncKey(const std::string &startSyncKey) { m_startSyncKey = startSyncKey; }
std::string getCurrentSyncKey() { return m_currentSyncKey; }
void setCurrentSyncKey(const std::string &currentSyncKey) { m_currentSyncKey = currentSyncKey; }
void findCollections(const std::string account, bool force_update);
std::string getCollectionPath(const std::string parentId, const std::string name);
std::string lookupFolder(std::string folder);
void findCollections(const std::string &account, bool force_update);
std::string lookupFolder(const std::string &folder);
boost::shared_ptr<ConfigNode> m_itemNode;
@ -229,7 +228,11 @@ class ActiveSyncSource :
bool pathFound;
ActiveSyncSource *source;
Collection() {pathFound = false;}
Collection() :
type(0),
pathFound(false),
source(NULL)
{}
int getFolderType();
bool collectionIsDefault();
@ -237,7 +240,8 @@ class ActiveSyncSource :
} collection;
std::map<std::string, Collection> m_collections; // Indexed by collectionID
std::map<std::string, std::string> m_folderPaths; // Maps pathName to collectionId
typedef std::map<std::string, std::string> FolderPaths;
FolderPaths m_folderPaths; // Maps pathName to collectionId
};
class ActiveSyncContactSource : public ActiveSyncSource