Repository: xbmc/xbmc
File: xbmc/video/dialogs/GUIDialogVideoInfo.cpp (C++)

Code before:
  bool finished = false;
  while (!finished)
  {
    if (ManageVideoItemArtwork(m_movieItem, m_movieItem->GetVideoInfoTag()->m_type, finished))
    {
      m_hasUpdatedThumb = true;

      // Update our screen
      Update();
    }
  };
}

// Allow user to select a Fanart
void CGUIDialogVideoInfo::OnGetFanart()
{
  CFileItemList items;

  // Ensure the fanart is unpacked
  m_movieItem->GetVideoInfoTag()->m_fanart.Unpack();

  if (m_movieItem->HasArt("fanart"))
  {
    CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false));
    itemCurrent->SetArt("thumb", m_movieItem->GetArt("fanart"));
    itemCurrent->SetArt("icon", "DefaultPicture.png");
    itemCurrent->SetLabel(g_localizeStrings.Get(20440));
    items.Add(itemCurrent);
  }

  std::string embeddedArt;
  if (URIUtils::HasExtension(m_movieItem->GetVideoInfoTag()->m_strFileNameAndPath, ".mkv"))
  {
    CFileItem item(m_movieItem->GetVideoInfoTag()->m_strFileNameAndPath, false);
    CVideoTagLoaderFFmpeg loader(item, nullptr, false);
    CVideoInfoTag tag;
    loader.Load(tag, false, nullptr);
    for (const auto& it : tag.m_coverArt)
    {
      if (it.m_type == "fanart")
      {
        CFileItemPtr itemF(new CFileItem("fanart://Embedded", false));
        embeddedArt = CTextureUtils::GetWrappedImageURL(item.GetPath(), "video_fanart");
        itemF->SetArt("thumb", embeddedArt);
        itemF->SetLabel(g_localizeStrings.Get(13520));
        items.Add(itemF);
      }
    }
  }

  // Grab the thumbnails from the web

Review comment (suggestion):
Better to use as:
```cpp
    if (URIUtils::HasExtension(fileNameAndPath, ".mkv|.mp4|.avi|.m4v") )
    {
```

The called function here https://github.com/xbmc/xbmc/blob/master/xbmc/utils/URIUtils.cpp#L91 already set to this way.

-------------

What you think to have a function to allow as this, maybe I can create a request for it?:
```cpp
        const std::vector<std::string> list = {
          ".mkv",
          ".mp4",
          ".avi",
          ".m4v"
        };
        if (URIUtils::HasExtension(fileNameAndPath, list))
        {
```
Have created this as test with new function and in vector it works really better :sweat_smile::
- CPU time 1 used: 0.393 ms (Your code by 1000 calls on Intel i7-9600)
- CPU time 2 used: 0.237 ms (To have with the `|` in one call code by 1000 calls)
- CPU time 3 used: 0.059 ms (To have with vector as static)
- CPU time 4 used: 0.093 ms (To have with non static vector)
```cpp
  std::string fileNameAndPath = "/home/alwin/test.mp4";
  double time_elapsed_ms_1 = 0.0;
  double time_elapsed_ms_2 = 0.0;
  double time_elapsed_ms_3 = 0.0;
  double time_elapsed_ms_4 = 0.0;

  for (int i = 0; i < 10; i++)
  {
    {
      std::clock_t c_start = std::clock();

      for (int i = 0; i < 100; i++)
      {
        URIUtils::HasExtension(fileNameAndPath, ".mkv");
        URIUtils::HasExtension(fileNameAndPath, ".mp4");
        URIUtils::HasExtension(fileNameAndPath, ".avi");
        URIUtils::HasExtension(fileNameAndPath, ".m4v");
      }

      std::clock_t c_end = std::clock();
      time_elapsed_ms_1 += 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC;
    }

    {
      std::clock_t c_start = std::clock();

      for (int i = 0; i < 100; i++)
      {
        URIUtils::HasExtension(fileNameAndPath, ".mkv|.mp4|.avi|.m4v");
      }

      std::clock_t c_end = std::clock();
      time_elapsed_ms_2 += 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC;
    }

    {
      std::clock_t c_start = std::clock();

      for (int i = 0; i < 100; i++)
      {
        static const std::vector<std::string> list = {
          ".mkv",
          ".mp4",
          ".avi",
          ".m4v"
        };
        URIUtils::HasExtension(fileNameAndPath, list);
      }

      std::clock_t c_end = std::clock();
      time_elapsed_ms_3 += 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC;
    }

    {
      std::clock_t c_start = std::clock();

      for (int i = 0; i < 100; i++)
      {
        const std::vector<std::string> list = {
          ".mkv",
          ".mp4",
          ".avi",
          ".m4v"
        };
        URIUtils::HasExtension(fileNameAndPath, list);
      }

      std::clock_t c_end = std::clock();
      time_elapsed_ms_4 += 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC;
    }
  }

  std::cout << "CPU time 1 used: " << time_elapsed_ms_1 << " ms\n";
  std::cout << "CPU time 2 used: " << time_elapsed_ms_2 << " ms\n";
  std::cout << "CPU time 3 used: " << time_elapsed_ms_3 << " ms\n";
  std::cout << "CPU time 4 used: " << time_elapsed_ms_4 << " ms\n";
```

Code after:
  bool finished = false;
  while (!finished)
  {
    if (ManageVideoItemArtwork(m_movieItem, m_movieItem->GetVideoInfoTag()->m_type, finished))
    {
      m_hasUpdatedThumb = true;

      // Update our screen
      Update();
    }
  };
}

namespace
{
std::string GetEmbeddedArt(const std::string& fileNameAndPath, const std::string& artType)
{
  std::string embeddedArt;
  if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
          CSettings::SETTING_MYVIDEOS_USETAGS))
  {
    if (URIUtils::HasExtension(fileNameAndPath, ".mkv") ||
        URIUtils::HasExtension(fileNameAndPath, ".mp4") ||
        URIUtils::HasExtension(fileNameAndPath, ".avi") ||
        URIUtils::HasExtension(fileNameAndPath, ".m4v"))
    {
      CFileItem item(fileNameAndPath, false);
      CVideoTagLoaderFFmpeg loader(item, nullptr, false);
      CVideoInfoTag tag;
      loader.Load(tag, false, nullptr);
      for (const auto& it : tag.m_coverArt)
      {
        if (it.m_type == artType)
        {
          embeddedArt = CTextureUtils::GetWrappedImageURL(fileNameAndPath, "video_" + artType);
          break;
        }
      }
    }
  }
  return embeddedArt;
}

} // unnamed namespace

// Allow user to select a Fanart
void CGUIDialogVideoInfo::OnGetFanart()
{
  CFileItemList items;

  // Ensure the fanart is unpacked