From: <sag...@us...> - 2015-06-07 19:38:08
|
Revision: 5266 http://sourceforge.net/p/modplug/code/5266 Author: saga-games Date: 2015-06-07 19:38:01 +0000 (Sun, 07 Jun 2015) Log Message: ----------- [Ref] Optimize advanced settings string copy overhead a bit more (no more senseless ustring -> CString conversion) and clean up the code a bit to remove some more redundancy. Modified Paths: -------------- trunk/OpenMPT/mptrack/AdvancedConfigDlg.cpp trunk/OpenMPT/mptrack/AdvancedConfigDlg.h Modified: trunk/OpenMPT/mptrack/AdvancedConfigDlg.cpp =================================================================== --- trunk/OpenMPT/mptrack/AdvancedConfigDlg.cpp 2015-06-07 18:06:40 UTC (rev 5265) +++ trunk/OpenMPT/mptrack/AdvancedConfigDlg.cpp 2015-06-07 19:38:01 UTC (rev 5266) @@ -57,29 +57,29 @@ int enableGroupsResult2 = static_cast<int>(ListView_EnableGroupView(m_List.m_hWnd, TRUE)); // Looks like we have to check enabling and check that a second enabling does // not change anything. - // Just checking if enabling fails with -1, does no work for older control + // Just checking if enabling fails with -1 does no work for older control // versions because they just do not know the window message at all and return // 0, always. At least Wine does behave this way. if(enableGroupsResult1 == 1 && enableGroupsResult2 == 0) { - m_ListGrouped = true; + m_listGrouped = true; } else { // Did not behave as documented or expected, the actual state of the // control is unknown by now. // Play safe and set and assume the traditional ungrouped mode again. ListView_EnableGroupView(m_List.m_hWnd, FALSE); - m_ListGrouped = false; + m_listGrouped = false; } - if(m_ListGrouped) + if(m_listGrouped) { const CListCtrlEx::Header headers[] = { { _T("Setting"), 100, LVCFMT_LEFT }, - { _T("Type"), 40, LVCFMT_LEFT }, + { _T("Type"), 40, LVCFMT_LEFT }, { _T("Value"), 190, LVCFMT_LEFT }, - { _T("Default"), 62, LVCFMT_LEFT }, + { _T("Default"), 62, LVCFMT_LEFT }, }; m_List.SetHeaders(headers); } else @@ -87,9 +87,9 @@ const CListCtrlEx::Header headers[] = { { _T("Setting"), 150, LVCFMT_LEFT }, - { _T("Type"), 40, LVCFMT_LEFT }, + { _T("Type"), 40, LVCFMT_LEFT }, { _T("Value"), 150, LVCFMT_LEFT }, - { _T("Default"), 52, LVCFMT_LEFT }, + { _T("Default"), 52, LVCFMT_LEFT }, }; m_List.SetHeaders(headers); } @@ -106,13 +106,28 @@ m_List.DeleteAllItems(); m_List.SetItemCount(theApp.GetSettings().size()); - m_IndexToPath.clear(); - m_IndexToPath.reserve(theApp.GetSettings().size()); - m_Groups.clear(); + m_indexToPath.clear(); + m_indexToPath.reserve(theApp.GetSettings().size()); + m_groups.clear(); int numGroups = 0; - CString findStr; - GetDlgItemText(IDC_EDIT1, findStr); + + CStringW findStr; + HWND findWnd = ::GetDlgItem(m_hWnd, IDC_EDIT1); + int findLen = ::GetWindowTextLengthW(findWnd); + ::GetWindowTextW(findWnd, findStr.GetBufferSetLength(findLen), findLen + 1); + findStr.ReleaseBuffer(); findStr.MakeLower(); + + LVITEMW lvi; + lvi.mask = LVIF_TEXT | LVIF_PARAM | (m_listGrouped ? LVIF_GROUPID : 0); + lvi.iSubItem = 0; + lvi.state = 0; + lvi.stateMask = 0; + lvi.cchTextMax = 0; + lvi.iImage = 0; + lvi.iIndent = 0; + lvi.iGroupId = 0; + int i = 0; for(SettingsContainer::SettingsMap::const_iterator it = theApp.GetSettings().begin(); it != theApp.GetSettings().end(); ++it) { @@ -123,19 +138,25 @@ const SettingValue &value = state.GetRefValue(); const SettingValue &defaultValue = state.GetRefDefault(); - bool addString = true; if(!findStr.IsEmpty()) { - CString str = mpt::ToCString(path.FormatAsString() + MPT_USTRING(" = ") + value.FormatValueAsString()); - addString = (str.MakeLower().Find(findStr) >= 0); + mpt::ustring str = path.FormatAsString() + MPT_USTRING("=") + value.FormatValueAsString(); + CStringW::StrTraits::StringLowercase(&str[0], str.size() + 1); + if(str.find(findStr) == mpt::ustring::npos) + { + continue; + } } - if(m_ListGrouped) + int index; + lvi.iItem = i++; + lvi.lParam = m_indexToPath.size(); + + if(m_listGrouped) { - int groupID = 0; - UNORDERED_MAP<mpt::ustring, int>::const_iterator gi = m_Groups.find(section); - if(gi == m_Groups.end()) + UNORDERED_MAP<mpt::ustring, int>::const_iterator gi = m_groups.find(section); + if(gi == m_groups.end()) { LVGROUP group; #if _WIN32_WINNT >= 0x0600 @@ -148,65 +169,33 @@ group.cchHeader = 0; group.pszFooter = nullptr; group.cchFooter = 0; - group.iGroupId = groupID = numGroups++; + group.iGroupId = lvi.iGroupId = numGroups++; group.stateMask = LVGS_COLLAPSIBLE; group.state = LVGS_COLLAPSIBLE; group.uAlign = LVGA_HEADER_LEFT; ListView_InsertGroup(m_List.m_hWnd, -1, &group); - m_Groups.insert(std::make_pair(section, groupID)); + m_groups.insert(std::make_pair(section, lvi.iGroupId)); } else { - groupID = gi->second; + lvi.iGroupId = gi->second; } - if(addString) - { - LVITEMW lvi; - lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_GROUPID; - lvi.iItem = i++; - lvi.iSubItem = 0; - lvi.state = 0; - lvi.stateMask = 0; - lvi.pszText = const_cast<wchar_t *>(key.c_str()); - lvi.cchTextMax = 0; - lvi.iImage = 0; - lvi.lParam = m_IndexToPath.size(); - lvi.iIndent = 0; - lvi.iGroupId = groupID; - int index = static_cast<int>(m_List.SendMessage(LVM_INSERTITEMW, 0, (LPARAM)(&lvi))); - m_List.SetItemText(index, 1, value.FormatTypeAsString().c_str()); - m_List.SetItemText(index, 2, value.FormatValueAsString().c_str()); - m_List.SetItemText(index, 3, defaultValue.FormatValueAsString().c_str()); - m_IndexToPath.push_back(path); - } + lvi.pszText = const_cast<wchar_t *>(key.c_str()); + index = static_cast<int>(m_List.SendMessage(LVM_INSERTITEMW, 0, (LPARAM)(&lvi))); } else { - if(addString) - { - const mpt::ustring sectionAndKey = path.FormatAsString(); - LVITEMW lvi; - lvi.mask = LVIF_TEXT | LVIF_PARAM; - lvi.iItem = i++; - lvi.iSubItem = 0; - lvi.state = 0; - lvi.stateMask = 0; - lvi.pszText = const_cast<wchar_t *>(sectionAndKey.c_str()); - lvi.cchTextMax = 0; - lvi.iImage = 0; - lvi.lParam = m_IndexToPath.size(); - lvi.iIndent = 0; - lvi.iGroupId = 0; - int index = static_cast<int>(m_List.SendMessage(LVM_INSERTITEMW, 0, (LPARAM)(&lvi))); - m_List.SetItemText(index, 1, value.FormatTypeAsString().c_str()); - m_List.SetItemText(index, 2, value.FormatValueAsString().c_str()); - m_List.SetItemText(index, 3, defaultValue.FormatValueAsString().c_str()); - m_IndexToPath.push_back(path); - } + const mpt::ustring sectionAndKey = path.FormatAsString(); + lvi.pszText = const_cast<wchar_t *>(sectionAndKey.c_str()); + index = static_cast<int>(m_List.SendMessage(LVM_INSERTITEMW, 0, (LPARAM)(&lvi))); } + m_List.SetItemText(index, 1, value.FormatTypeAsString().c_str()); + m_List.SetItemText(index, 2, value.FormatValueAsString().c_str()); + m_List.SetItemText(index, 3, defaultValue.FormatValueAsString().c_str()); + m_indexToPath.push_back(path); } m_List.SetItemCount(i); @@ -235,7 +224,7 @@ //--------------------------------------------------------- { const int index = m_List.GetSelectionMark(); - const SettingPath path = m_IndexToPath[m_List.GetItemData(index)]; + const SettingPath path = m_indexToPath[m_List.GetItemData(index)]; SettingValue val = theApp.GetSettings().GetMap().find(path)->second; if(val.GetType() == SettingTypeBool) { Modified: trunk/OpenMPT/mptrack/AdvancedConfigDlg.h =================================================================== --- trunk/OpenMPT/mptrack/AdvancedConfigDlg.h 2015-06-07 18:06:40 UTC (rev 5265) +++ trunk/OpenMPT/mptrack/AdvancedConfigDlg.h 2015-06-07 19:38:01 UTC (rev 5266) @@ -28,12 +28,12 @@ { protected: CListCtrlEx m_List; - bool m_ListGrouped; - std::vector<SettingPath> m_IndexToPath; - UNORDERED_MAP<mpt::ustring, int> m_Groups; + std::vector<SettingPath> m_indexToPath; + UNORDERED_MAP<mpt::ustring, int> m_groups; + bool m_listGrouped; public: - COptionsAdvanced():CPropertyPage(IDD_OPTIONS_ADVANCED), m_ListGrouped(false) {} + COptionsAdvanced():CPropertyPage(IDD_OPTIONS_ADVANCED), m_listGrouped(false) {} protected: virtual BOOL OnInitDialog(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |