Repository: xbmc/xbmc
File: xbmc/pvr/guilib/PVRGUIChannelIconUpdater.cpp (C++)

Code before:
using namespace PVR;

void CPVRGUIChannelIconUpdater::SearchAndUpdateMissingChannelIcons() const
{
  const std::string iconPath = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_PVRMENU_ICONPATH);
  if (iconPath.empty())
    return;

  // fetch files in icon path for fast lookup
  CFileItemList fileItemList;
  XFILE::CDirectory::GetDirectory(iconPath, fileItemList, ".jpg|.png|.tbn", XFILE::DIR_FLAG_DEFAULTS);

  if (fileItemList.IsEmpty())
    return;

  CLog::Log(LOGINFO, "Starting PVR channel icon search");

  // create a map for fast lookup of normalized file base name
  using FileNamesMap = std::map<std::string, std::string, std::less<>>;
  FileNamesMap fileItemMap;
  for (const auto& item : fileItemList)
  {
    std::string baseName = URIUtils::GetFileName(item->GetPath());
    URIUtils::RemoveExtension(baseName);
    StringUtils::ToLower(baseName);
    fileItemMap.try_emplace(baseName, item->GetPath());
  }

  std::unique_ptr<CPVRGUIProgressHandler> progressHandler;
  if (!m_groups.empty())
    progressHandler = std::make_unique<CPVRGUIProgressHandler>(
        g_localizeStrings.Get(19286)); // Searching for channel icons

  for (const auto& group : m_groups)
  {
    const std::vector<std::shared_ptr<CPVRChannelGroupMember>> members = group->GetMembers();
    size_t channelIndex = 0;
    for (const auto& member : members)
    {
      const std::shared_ptr<CPVRChannel> channel = member->Channel();

      progressHandler->UpdateProgress(channel->ChannelName(), channelIndex, members.size());
      channelIndex++;

      // skip if an icon is already set and exists
      if (CFileUtils::Exists(channel->IconPath()))
        continue;

      // reset icon before searching for a new one
      channel->SetIconPath("");


Review comment (suggestion):
Possible optimization:
```suggestion
    fileItemMap.try_emplace(std::move(baseName), item->GetPath());
```

Code after:
using namespace PVR;

void CPVRGUIChannelIconUpdater::SearchAndUpdateMissingChannelIcons() const
{
  const std::string iconPath = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_PVRMENU_ICONPATH);
  if (iconPath.empty())
    return;

  // fetch files in icon path for fast lookup
  CFileItemList fileItemList;
  XFILE::CDirectory::GetDirectory(iconPath, fileItemList, ".jpg|.png|.tbn", XFILE::DIR_FLAG_DEFAULTS);

  if (fileItemList.IsEmpty())
    return;

  CLog::Log(LOGINFO, "Starting PVR channel icon search");

  // create a map for fast lookup of normalized file base name
  using FileNamesMap = std::map<std::string, std::string, std::less<>>;
  FileNamesMap fileItemMap;
  for (const auto& item : fileItemList)
  {
    std::string baseName = URIUtils::GetFileName(item->GetPath());
    URIUtils::RemoveExtension(baseName);
    StringUtils::ToLower(baseName);
    fileItemMap.try_emplace(std::move(baseName), item->GetPath());
  }

  std::unique_ptr<CPVRGUIProgressHandler> progressHandler;
  if (!m_groups.empty())
    progressHandler = std::make_unique<CPVRGUIProgressHandler>(
        g_localizeStrings.Get(19286)); // Searching for channel icons

  for (const auto& group : m_groups)
  {
    const std::vector<std::shared_ptr<CPVRChannelGroupMember>> members = group->GetMembers();
    size_t channelIndex = 0;
    for (const auto& member : members)
    {
      const std::shared_ptr<CPVRChannel> channel = member->Channel();

      progressHandler->UpdateProgress(channel->ChannelName(), channelIndex, members.size());
      channelIndex++;

      // skip if an icon is already set and exists
      if (CFileUtils::Exists(channel->IconPath()))
        continue;

      // reset icon before searching for a new one
      channel->SetIconPath("");