mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 00:20:06 +02:00
Don't eliminate indirection for CommandListEntry. Explain why. Use unique_ptr
This commit is contained in:
parent
ca53b191b1
commit
00db530c9b
@ -415,7 +415,7 @@ void CommandManager::PurgeData()
|
||||
// mCommandList contains pointers to CommandListEntrys
|
||||
// mMenuBarList contains MenuBarListEntrys.
|
||||
// mSubMenuList contains SubMenuListEntrys
|
||||
WX_CLEAR_ARRAY( mCommandList );
|
||||
mCommandList.clear();
|
||||
mMenuBarList.clear();
|
||||
mSubMenuList.clear();
|
||||
|
||||
@ -799,7 +799,8 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
|
||||
int index,
|
||||
int count)
|
||||
{
|
||||
CommandListEntry *entry = new CommandListEntry;
|
||||
{
|
||||
auto entry = std::make_unique<CommandListEntry>();
|
||||
|
||||
wxString labelPrefix;
|
||||
if (!mSubMenuList.empty()) {
|
||||
@ -858,7 +859,12 @@ CommandListEntry *CommandManager::NewIdentifier(const wxString & name,
|
||||
}
|
||||
gPrefs->SetPath(wxT("/"));
|
||||
|
||||
mCommandList.Add(entry);
|
||||
mCommandList.push_back(std::move(entry));
|
||||
// Don't use the variable entry eny more!
|
||||
}
|
||||
|
||||
// New variable
|
||||
CommandListEntry *entry = &*mCommandList.back();
|
||||
mCommandIDHash[entry->id] = entry;
|
||||
|
||||
#if defined(__WXDEBUG__)
|
||||
@ -965,8 +971,7 @@ void CommandManager::EnableUsingFlags(wxUint32 flags, wxUint32 mask)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<mCommandList.GetCount(); i++) {
|
||||
CommandListEntry *entry = mCommandList[i];
|
||||
for(const auto &entry : mCommandList) {
|
||||
if (entry->multi && entry->index != 0)
|
||||
continue;
|
||||
|
||||
@ -974,7 +979,7 @@ void CommandManager::EnableUsingFlags(wxUint32 flags, wxUint32 mask)
|
||||
if (combinedMask) {
|
||||
bool enable = ((flags & combinedMask) ==
|
||||
(entry->flags & combinedMask));
|
||||
Enable(entry, enable);
|
||||
Enable(entry.get(), enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1020,7 +1025,7 @@ void CommandManager::SetKeyFromName(wxString name, wxString key)
|
||||
|
||||
void CommandManager::SetKeyFromIndex(int i, wxString key)
|
||||
{
|
||||
CommandListEntry *entry = mCommandList[i];
|
||||
const auto &entry = mCommandList[i];
|
||||
entry->key = KeyStringNormalize(key);
|
||||
}
|
||||
|
||||
@ -1154,13 +1159,13 @@ bool CommandManager::HandleTextualCommand(wxString & Str, wxUint32 flags, wxUint
|
||||
unsigned int i;
|
||||
|
||||
// Linear search for now...
|
||||
for (i = 0; i < mCommandList.GetCount(); i++)
|
||||
for (const auto &entry : mCommandList)
|
||||
{
|
||||
if (!mCommandList[i]->multi)
|
||||
if (!entry->multi)
|
||||
{
|
||||
if( Str.IsSameAs( mCommandList[i]->name ))
|
||||
if( Str.IsSameAs( entry->name ))
|
||||
{
|
||||
return HandleCommandEntry( mCommandList[i], flags, mask);
|
||||
return HandleCommandEntry( entry.get(), flags, mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1192,10 +1197,8 @@ void CommandManager::GetCategories(wxArrayString &cats)
|
||||
{
|
||||
cats.Clear();
|
||||
|
||||
size_t cnt = mCommandList.GetCount();
|
||||
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
wxString cat = mCommandList[i]->labelTop;
|
||||
for (const auto &entry : mCommandList) {
|
||||
wxString cat = entry->labelTop;
|
||||
if (cats.Index(cat) == wxNOT_FOUND) {
|
||||
cats.Add(cat);
|
||||
}
|
||||
@ -1224,26 +1227,22 @@ void CommandManager::GetCategories(wxArrayString &cats)
|
||||
void CommandManager::GetAllCommandNames(wxArrayString &names,
|
||||
bool includeMultis)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<mCommandList.GetCount(); i++) {
|
||||
if (!mCommandList[i]->multi)
|
||||
names.Add(mCommandList[i]->name);
|
||||
for(const auto &entry : mCommandList) {
|
||||
if (!entry->multi)
|
||||
names.Add(entry->name);
|
||||
else if( includeMultis )
|
||||
names.Add(mCommandList[i]->name + wxT(":")/*+ mCommandList[i]->label*/);
|
||||
names.Add(entry->name + wxT(":")/*+ mCommandList[i]->label*/);
|
||||
}
|
||||
}
|
||||
|
||||
void CommandManager::GetAllCommandLabels(wxArrayString &names,
|
||||
bool includeMultis)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<mCommandList.GetCount(); i++) {
|
||||
if (!mCommandList[i]->multi)
|
||||
names.Add(mCommandList[i]->label);
|
||||
for(const auto &entry : mCommandList) {
|
||||
if (!entry->multi)
|
||||
names.Add(entry->label);
|
||||
else if( includeMultis )
|
||||
names.Add(mCommandList[i]->label);
|
||||
names.Add(entry->label);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1258,29 +1257,27 @@ void CommandManager::GetAllCommandData(
|
||||
#endif
|
||||
bool includeMultis)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<mCommandList.GetCount(); i++) {
|
||||
if (!mCommandList[i]->multi)
|
||||
for(const auto &entry : mCommandList) {
|
||||
if (!entry->multi)
|
||||
{
|
||||
names.Add(mCommandList[i]->name);
|
||||
keys.Add(mCommandList[i]->key);
|
||||
default_keys.Add( mCommandList[i]->defaultKey);
|
||||
labels.Add(mCommandList[i]->label);
|
||||
categories.Add(mCommandList[i]->labelTop);
|
||||
names.Add(entry->name);
|
||||
keys.Add(entry->key);
|
||||
default_keys.Add(entry->defaultKey);
|
||||
labels.Add(entry->label);
|
||||
categories.Add(entry->labelTop);
|
||||
#if defined(EXPERIMENTAL_KEY_VIEW)
|
||||
prefixes.Add(mCommandList[i]->labelPrefix);
|
||||
prefixes.Add(entry->labelPrefix);
|
||||
#endif
|
||||
}
|
||||
else if( includeMultis )
|
||||
{
|
||||
names.Add(mCommandList[i]->name);
|
||||
keys.Add(mCommandList[i]->key);
|
||||
default_keys.Add( mCommandList[i]->defaultKey);
|
||||
labels.Add(mCommandList[i]->label);
|
||||
categories.Add(mCommandList[i]->labelTop);
|
||||
names.Add(entry->name);
|
||||
keys.Add(entry->key);
|
||||
default_keys.Add(entry->defaultKey);
|
||||
labels.Add(entry->label);
|
||||
categories.Add(entry->labelTop);
|
||||
#if defined(EXPERIMENTAL_KEY_VIEW)
|
||||
prefixes.Add(mCommandList[i]->labelPrefix);
|
||||
prefixes.Add(entry->labelPrefix);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -1389,19 +1386,17 @@ XMLTagHandler *CommandManager::HandleXMLChild(const wxChar * WXUNUSED(tag))
|
||||
|
||||
void CommandManager::WriteXML(XMLWriter &xmlFile)
|
||||
{
|
||||
unsigned int j;
|
||||
|
||||
xmlFile.StartTag(wxT("audacitykeyboard"));
|
||||
xmlFile.WriteAttr(wxT("audacityversion"), AUDACITY_VERSION_STRING);
|
||||
|
||||
for(j=0; j<mCommandList.GetCount(); j++) {
|
||||
wxString label = mCommandList[j]->label;
|
||||
for(const auto &entry : mCommandList) {
|
||||
wxString label = entry->label;
|
||||
label = wxMenuItem::GetLabelText(label.BeforeFirst(wxT('\t')));
|
||||
|
||||
xmlFile.StartTag(wxT("command"));
|
||||
xmlFile.WriteAttr(wxT("name"), mCommandList[j]->name);
|
||||
xmlFile.WriteAttr(wxT("name"), entry->name);
|
||||
xmlFile.WriteAttr(wxT("label"), label);
|
||||
xmlFile.WriteAttr(wxT("key"), mCommandList[j]->key);
|
||||
xmlFile.WriteAttr(wxT("key"), entry->key);
|
||||
xmlFile.EndTag(wxT("command"));
|
||||
}
|
||||
|
||||
@ -1450,7 +1445,7 @@ void CommandManager::SetCommandFlags(wxUint32 flags, wxUint32 mask, ...)
|
||||
#if defined(__WXDEBUG__)
|
||||
void CommandManager::CheckDups()
|
||||
{
|
||||
int cnt = mCommandList.GetCount();
|
||||
int cnt = mCommandList.size();
|
||||
for (size_t j = 0; (int)j < cnt; j++) {
|
||||
if (mCommandList[j]->key.IsEmpty()) {
|
||||
continue;
|
||||
|
@ -79,7 +79,10 @@ struct CommandListEntry
|
||||
|
||||
using MenuBarList = std::vector < MenuBarListEntry >;
|
||||
using SubMenuList = std::vector < SubMenuListEntry >;
|
||||
WX_DEFINE_USER_EXPORTED_ARRAY(CommandListEntry *, CommandList, class AUDACITY_DLL_API);
|
||||
|
||||
// This is an array of pointers, not structures, because the hash maps also point to them,
|
||||
// so we don't want the structures to relocate with vector operations.
|
||||
using CommandList = std::vector < std::unique_ptr<CommandListEntry> > ;
|
||||
|
||||
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(CommandListEntry *, CommandNameHash, class AUDACITY_DLL_API);
|
||||
WX_DECLARE_HASH_MAP_WITH_DECL(int, CommandListEntry *, wxIntegerHash, wxIntegerEqual, CommandIDHash, class AUDACITY_DLL_API);
|
||||
@ -97,6 +100,9 @@ class AUDACITY_DLL_API CommandManager: public XMLTagHandler
|
||||
CommandManager();
|
||||
virtual ~CommandManager();
|
||||
|
||||
CommandManager(const CommandManager&) = delete;
|
||||
CommandManager &operator= (const CommandManager&) = delete;
|
||||
|
||||
void PurgeData();
|
||||
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user