@@ -253,6 +253,28 @@ const std::string& LLView::getName() const
253253 return mName .empty () ? no_name : mName ;
254254}
255255
256+ void LLView::setName (const std::string& name)
257+ {
258+ if (name == mName )
259+ {
260+ return ;
261+ }
262+
263+ LLView* parent = mParentView ;
264+
265+ if (parent && !mName .empty ())
266+ {
267+ parent->mChildNameCache .erase (mName );
268+ }
269+
270+ mName = name;
271+
272+ if (parent && !mName .empty ())
273+ {
274+ parent->mChildNameCache [mName ] = this ;
275+ }
276+ }
277+
256278void LLView::sendChildToFront (LLView* child)
257279{
258280// llassert_always(sDepth == 0); // Avoid re-ordering while drawing; it can cause subtle iterator bugs
@@ -306,7 +328,7 @@ bool LLView::addChild(LLView* child, S32 tab_group)
306328 mChildList .push_front (child);
307329
308330 // Add to name cache for fast lookup
309- if (! child->getName (). empty ())
331+ if (child->hasName ())
310332 {
311333 mChildNameCache [child->getName ()] = child;
312334 }
@@ -352,7 +374,7 @@ void LLView::removeChild(LLView* child)
352374 mChildList .remove ( child );
353375
354376 // Remove from name cache
355- if (! child->getName (). empty ())
377+ if (child->hasName ())
356378 {
357379 mChildNameCache .erase (child->getName ());
358380 }
@@ -1663,10 +1685,14 @@ LLView* LLView::findChildView(std::string_view name, bool recurse) const
16631685 LL_PROFILE_ZONE_SCOPED_CATEGORY_UI;
16641686
16651687 // Check cache first for direct children - O(1) lookup instead of O(n)
1666- auto cache_it = mChildNameCache .find (name);
1667- if (cache_it != mChildNameCache .end ())
1688+ if (!mChildNameCache .empty ())
16681689 {
1669- return cache_it->second ;
1690+ std::string lookup_key (name);
1691+ auto cache_it = mChildNameCache .find (lookup_key);
1692+ if (cache_it != mChildNameCache .end ())
1693+ {
1694+ return cache_it->second ;
1695+ }
16701696 }
16711697
16721698 // Look for direct children *first*
@@ -1676,7 +1702,10 @@ LLView* LLView::findChildView(std::string_view name, bool recurse) const
16761702 if (childp->getName () == name)
16771703 {
16781704 // Cache the result for next lookup
1679- mChildNameCache [name] = childp;
1705+ if (childp->hasName ())
1706+ {
1707+ mChildNameCache [childp->getName ()] = childp;
1708+ }
16801709 return childp;
16811710 }
16821711 }
0 commit comments