// 2 is LAYER_3D + Clipping
const int comparitorIndex = layer.GetBehavior() == Dali::Layer::LAYER_3D ? respectClippingOrder ? 2u : 1u : 0u;
+ bool needToSort = false;
+
for(uint32_t index = 0; index < renderableCount; ++index)
{
RenderItemKey itemKey = renderList.GetItemKey(index);
// Keep the renderitem pointer in the helper so we can quickly reorder items after sort.
mSortingHelper[index].renderItem = itemKey;
+
+ if(!needToSort && index > 0u)
+ {
+ // Check if we need to sort the list.
+ // We only need to sort if the depth index is not the same as the previous item.
+ // This is a fast way of checking if we need to sort.
+ if(mSortComparitors[comparitorIndex](mSortingHelper[index], mSortingHelper[index - 1u]))
+ {
+ needToSort = true;
+ }
+ }
}
- std::stable_sort(mSortingHelper.begin(), mSortingHelper.end(), mSortComparitors[comparitorIndex]);
+ // If we don't need to sort, we can skip the sort.
+ if(needToSort)
+ {
+ std::stable_sort(mSortingHelper.begin(), mSortingHelper.end(), mSortComparitors[comparitorIndex]);
+ }
// Reorder / re-populate the RenderItems in the RenderList to correct order based on the sortinghelper.
DALI_LOG_INFO(gRenderListLogFilter, Debug::Verbose, "Sorted Transparent List:\n");