ENH: Changed m_Indices to an stl set and renamed it to m_IndexSet. Using a set results in a significant performance increase and reduction in memory usage.

This commit is contained in:
Brad King 2001-04-16 12:31:56 -04:00
parent e963dcaa8f
commit f63e4a144c
2 changed files with 11 additions and 31 deletions

View File

@ -98,14 +98,12 @@ void cmMakeDepend::DoDepends()
i != m_DependInformation.end(); ++i) i != m_DependInformation.end(); ++i)
{ {
cmDependInformation* info = *i; cmDependInformation* info = *i;
// Remove duplicate depends
info->RemoveDuplicateIndices();
// find the class // find the class
if(info->m_ClassFileIndex != 0) if(info->m_ClassFileIndex != 0)
{ {
cmClassFile& cfile = *(info->m_ClassFileIndex); cmClassFile& cfile = *(info->m_ClassFileIndex);
for( std::vector<int>::iterator indx = info->m_Indices.begin(); for( cmDependInformation::IndexSet::const_iterator indx = info->m_IndexSet.begin();
indx != info->m_Indices.end(); ++indx) indx != info->m_IndexSet.end(); ++indx)
{ {
cfile.m_Depends.push_back(m_DependInformation[*indx]->m_FullPath); cfile.m_Depends.push_back(m_DependInformation[*indx]->m_FullPath);
} }
@ -164,7 +162,7 @@ void cmMakeDepend::Depend(cmDependInformation* info)
// Found dependency information. We are done. // Found dependency information. We are done.
return; return;
} }
} }
// Couldn't find any dependency information. // Couldn't find any dependency information.
@ -244,7 +242,7 @@ void cmMakeDepend::AddDependency(cmDependInformation* info, const char* file)
int index = this->FindInformation(file); int index = this->FindInformation(file);
// add the index to the depends of the current // add the index to the depends of the current
// depend info object // depend info object
info->m_Indices.push_back(index); info->m_IndexSet.insert(index);
// Get the depend information object for the include file // Get the depend information object for the include file
cmDependInformation* dependInfo = m_DependInformation[index]; cmDependInformation* dependInfo = m_DependInformation[index];
// if the depends are not known for an include file, then compute them // if the depends are not known for an include file, then compute them
@ -286,28 +284,13 @@ int cmMakeDepend::FindInformation(const char* fname)
return m_DependInformation.size()-1; return m_DependInformation.size()-1;
} }
// remove duplicate indices from the depend information
void cmDependInformation::RemoveDuplicateIndices()
{
// sort the array
std::sort(m_Indices.begin(), m_Indices.end(), std::less<int>());
// remove duplicates
std::vector<int>::iterator new_end =
std::unique(m_Indices.begin(), m_Indices.end());
m_Indices.erase(new_end, m_Indices.end());
}
// add the depend information from info to the m_Indices varible of this class. // add the depend information from info to the m_IndexSet varible of this class.
void cmDependInformation::MergeInfo(cmDependInformation* info) void cmDependInformation::MergeInfo(cmDependInformation* info)
{ {
if(this == info) if(this != info)
{ {
return; m_IndexSet.insert(info->m_IndexSet.begin(), info->m_IndexSet.end());
}
std::vector<int>::iterator i = info->m_Indices.begin();
for(; i!= info->m_Indices.end(); ++i)
{
m_Indices.push_back(*i);
} }
} }

View File

@ -39,10 +39,12 @@ struct cmDependInformation
} }
/** /**
* A list of indices into the m_DependInformation array of cmMakeDepend. * A set of indices into the m_DependInformation array of cmMakeDepend.
* The index represents the files that this file depends on. * The index represents the files that this file depends on.
* This must be a "set" to keep indices unique.
*/ */
std::vector<int> m_Indices; typedef std::set<int> IndexSet;
IndexSet m_IndexSet;
/** /**
* Full path to this file. * Full path to this file.
@ -70,11 +72,6 @@ struct cmDependInformation
* This method adds the dependencies of another file to this one. * This method adds the dependencies of another file to this one.
*/ */
void MergeInfo(cmDependInformation*); void MergeInfo(cmDependInformation*);
/**
* This method removes duplicate depends from the index list.
*/
void RemoveDuplicateIndices();
}; };