From b0a9be01890578d239bcb958dec33c301986519d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dobrakowski?= Date: Mon, 10 Mar 2025 11:14:17 +0100 Subject: [PATCH] tdf#153294 Optimize item index retrieval in Menu::GetCharacterBounds() using std::find. Change-Id: Ia72d77025ea0308e336d0b0b5497fedada7e73cd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182729 Reviewed-by: Michael Weghorn Tested-by: Jenkins --- vcl/source/window/menu.cxx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index 8603eb183a11..e3df90c51920 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -2265,13 +2265,10 @@ tools::Rectangle Menu::GetCharacterBounds( sal_uInt16 nItemID, tools::Long nInde ImplFillLayoutData(); if( mpLayoutData ) { - for( size_t i = 0; i < mpLayoutData->m_aLineItemIds.size(); i++ ) + auto it = std::find(mpLayoutData->m_aLineItemIds.begin(), mpLayoutData->m_aLineItemIds.end(), nItemID); + if (it != mpLayoutData->m_aLineItemIds.end()) { - if( mpLayoutData->m_aLineItemIds[i] == nItemID ) - { - nItemIndex = mpLayoutData->m_aLineIndices[i]; - break; - } + nItemIndex = mpLayoutData->m_aLineIndices[std::distance(mpLayoutData->m_aLineItemIds.begin(), it)]; } } return (mpLayoutData && nItemIndex != -1) ? mpLayoutData->GetCharacterBounds( nItemIndex+nIndex ) : tools::Rectangle();