Thanks to Thomas, I realized why Code::Blocks "freezes" for a couple of seconds when you save files.
bool Parser::Reparse(const wxString& filename, bool isLocal)
{
if (!Done())
return false; // if still parsing, exit with error
wxString file = UnixFilename(filename);
// Manager::Get()->GetMessageManager()->DebugLog(_("Reparsing %s"), file.c_str());
RemoveFile(file);
ClearTemporaries();
ReCreateTree();
{
wxCriticalSectionLocker lock(s_mutexListProtection);
m_ReparsedFiles.Add(file);
}
return Parse(file, isLocal);
}
bool Parser::RemoveFile(const wxString& filename)
{
wxCriticalSectionLocker lock(s_mutexListProtection);
wxCriticalSectionLocker lock1(s_mutexProtection);
wxString file = UnixFilename(filename);
if (m_ParsedFiles.Index(file) != wxNOT_FOUND)
{
// only if it has been parsed before...
// delete any entries that belong to the file in question
// FIXME: what happens with entries *linked* to this entry?
unsigned int i = 0;
while (i < m_Tokens.GetCount())
{
if (m_Tokens[i]->m_Filename.Matches(file))
m_Tokens.RemoveAt(i);
else
++i;
}
m_ParsedFiles.Remove(file);
}
else
return false;
return true;
}
void Parser::ClearTemporaries()
{
if (!Done())
return;
unsigned int i = 0;
while (i < m_Tokens.GetCount())
{
Token* token = m_Tokens[i];
if (token->m_IsTemporary)
m_Tokens.RemoveAt(i);
else
++i;
}
}
void Parser::ReCreateTree()
{
m_TokensTree.Clear();
unsigned int i;
for(i = 0; i < m_Tokens.GetCount();i++)
{
m_TokensTree.AddToken(m_Tokens[i]->m_Name,m_Tokens[i]);
}
}
The ReCreateTree was added by Moi, as a quick hack to sync the Tree and the TokensArray.
But if all this is done once PER file, ugh :(