From 224286b32587fe9a5db4a7f18b93956a0865d42d Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 7 Mar 2023 11:19:19 +0000 Subject: svx: Stop manually counting map entries The `nCount` member counts the number of elements in `m_aItemList`, but `std::unordered_map::size()` also returns that, so just use that instead. Use `SvxSearchCharSet::getMaxCharCount` in most places and simplify to use `std::min` in `SvxSearchCharSet::LastInView`. Change-Id: I8b66b1d83c0327026b13147f201995c7d1df1238 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148422 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- include/svx/searchcharmap.hxx | 2 -- svx/source/dialog/searchcharmap.cxx | 17 ++++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/include/svx/searchcharmap.hxx b/include/svx/searchcharmap.hxx index 33d7432096d8..7ebc8ce5ab2c 100644 --- a/include/svx/searchcharmap.hxx +++ b/include/svx/searchcharmap.hxx @@ -54,8 +54,6 @@ public: virtual sal_Int32 getMaxCharCount() const override; private: - sal_Int32 nCount; - //index to char code mapping for the search //to uniquely identify each appended element std::unordered_map m_aItemList; diff --git a/svx/source/dialog/searchcharmap.cxx b/svx/source/dialog/searchcharmap.cxx index ea2ae309735a..02fb19be20b0 100644 --- a/svx/source/dialog/searchcharmap.cxx +++ b/svx/source/dialog/searchcharmap.cxx @@ -40,7 +40,6 @@ using namespace ::com::sun::star; SvxSearchCharSet::SvxSearchCharSet(std::unique_ptr pScrolledWindow, const VclPtr& rVirDev) : SvxShowCharSet(std::move(pScrolledWindow), rVirDev) - , nCount(0) { } @@ -48,10 +47,7 @@ int SvxSearchCharSet::LastInView() const { int nIndex = FirstInView(); nIndex += ROW_COUNT * COLUMN_COUNT - 1; - int nCompare = nCount - 1; - if (nIndex > nCompare) - nIndex = nCompare; - return nIndex; + return std::min(nIndex, getMaxCharCount() -1); } bool SvxSearchCharSet::KeyInput(const KeyEvent& rKEvt) @@ -92,7 +88,7 @@ bool SvxSearchCharSet::KeyInput(const KeyEvent& rKEvt) tmpSelected = 0; break; case KEY_END: - tmpSelected = nCount - 1; + tmpSelected = getMaxCharCount() - 1; break; case KEY_TAB: // some fonts have a character at these unicode control codes case KEY_ESCAPE: @@ -333,7 +329,7 @@ void SvxSearchCharSet::RecalculateFont(vcl::RenderContext& rRenderContext) nY = aSize.Height() / ROW_COUNT; //scrollbar settings -- error - int nLastRow = (nCount - 1 + COLUMN_COUNT) / COLUMN_COUNT; + int nLastRow = (getMaxCharCount() - 1 + COLUMN_COUNT) / COLUMN_COUNT; mxScrollArea->vadjustment_configure(mxScrollArea->vadjustment_get_value(), 0, nLastRow, 1, ROW_COUNT - 1, ROW_COUNT); // rearrange CharSet element in sync with nX- and nY-multiples @@ -371,7 +367,7 @@ void SvxSearchCharSet::SelectIndex(int nNewIndex, bool bFocus) int nDelta = (nNewIndex - LastInView() + COLUMN_COUNT) / COLUMN_COUNT; mxScrollArea->vadjustment_set_value(nOldPos + nDelta); - if( nNewIndex < nCount ) + if (nNewIndex < getMaxCharCount()) { nSelectedIndex = nNewIndex; Invalidate(); @@ -443,19 +439,18 @@ svx::SvxShowCharSetItem* SvxSearchCharSet::ImplGetItem( int _nPos ) sal_Int32 SvxSearchCharSet::getMaxCharCount() const { - return nCount; + return m_aItemList.size(); } void SvxSearchCharSet::ClearPreviousData() { m_aItemList.clear(); - nCount = 0; Invalidate(); } void SvxSearchCharSet::AppendCharToList(sal_UCS4 sChar) { - m_aItemList.insert(std::make_pair(nCount++, sChar)); + m_aItemList.insert(std::make_pair(m_aItemList.size(), sChar)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit