Repository: xbmc/xbmc
File: xbmc/PlayListPlayer.cpp (C++)

Code before:
      if (list->Size() > 0)
      {
        Id playlistId = Id::TYPE_MUSIC;
        for (int i = 0; i < list->Size(); i++)
        {
          if (IsVideo(*list->Get(i)))
          {
            playlistId = Id::TYPE_VIDEO;
            break;
          }
        }

        ClearPlaylist(playlistId);
        SetCurrentPlaylist(playlistId);
        if (list->Size() == 1 && !IsPlayList(*list->Get(0)))
        {
          CFileItemPtr item = (*list)[0];
          // if the item is a plugin we need to resolve the URL to ensure the infotags are filled.
          if (URIUtils::HasPluginPath(*item) &&
              !XFILE::CPluginDirectory::GetResolvedPluginResult(*item))
          {
            return;
          }
          if (MUSIC::IsAudio(*item) || IsVideo(*item))
          {
            if ((IsVideo(*item) && !g_passwordManager.IsVideoUnlocked()) ||
                (MUSIC::IsAudio(*item) && !g_passwordManager.IsMusicUnlocked()))
            {
              CLog::LogF(LOGERROR,
                         "MasterCode or MediaSource-code is wrong: {} will not be played.",
                         item->GetPath());
              return;
            }
            Play(item, pMsg->strParam);
          }
          else
            g_application.PlayMedia(*item, pMsg->strParam, playlistId);
        }
        else
        {
          // Handle "shuffled" option if present
          if (list->HasProperty("shuffled") && list->GetProperty("shuffled").isBoolean())
            SetShuffle(playlistId, list->GetProperty("shuffled").asBoolean(), false);
          // Handle "repeat" option if present
          if (list->HasProperty("repeat") && list->GetProperty("repeat").isInteger())
            SetRepeat(playlistId, static_cast<RepeatState>(list->GetProperty("repeat").asInteger()),
                      false);

          Add(playlistId, (*list));
          Play(pMsg->param1, pMsg->strParam);
        }

Review comment (performance):
On more: Please take a look into implementation of IsVideo() and you will see that it is quite complex, thus expensive, cpu cycle wise. I suggest to calculate it only once and to store the result in a variable.

Code after:
      if (list->Size() > 0)
      {
        Id playlistId = Id::TYPE_MUSIC;
        for (int i = 0; i < list->Size(); i++)
        {
          if (IsVideo(*list->Get(i)))
          {
            playlistId = Id::TYPE_VIDEO;
            break;
          }
        }

        ClearPlaylist(playlistId);
        SetCurrentPlaylist(playlistId);
        if (list->Size() == 1 && !IsPlayList(*list->Get(0)))
        {
          CFileItemPtr item = (*list)[0];
          // if the item is a plugin we need to resolve the URL to ensure the infotags are filled.
          if (URIUtils::HasPluginPath(*item) &&
              !XFILE::CPluginDirectory::GetResolvedPluginResult(*item))
          {
            return;
          }
          const bool isVideo{VIDEO::IsVideo(*item)};
          const bool isAudio{MUSIC::IsAudio(*item)};
          if (isAudio || isVideo)
          {
            if ((isVideo && !g_passwordManager.IsVideoUnlocked()) ||
                (isAudio && !g_passwordManager.IsMusicUnlocked()))
            {
              CLog::LogF(LOGERROR,
                         "MasterCode or MediaSource-code is wrong: {} will not be played.",
                         item->GetPath());
              return;
            }
            Play(item, pMsg->strParam);
          }
          else
            g_application.PlayMedia(*item, pMsg->strParam, playlistId);
        }
        else
        {
          // Handle "shuffled" option if present
          if (list->HasProperty("shuffled") && list->GetProperty("shuffled").isBoolean())
            SetShuffle(playlistId, list->GetProperty("shuffled").asBoolean(), false);
          // Handle "repeat" option if present
          if (list->HasProperty("repeat") && list->GetProperty("repeat").isInteger())
            SetRepeat(playlistId, static_cast<RepeatState>(list->GetProperty("repeat").asInteger()),
                      false);

          Add(playlistId, (*list));