ronantakizawa/codereview-bench huggingface dataset:
Repository: xbmc/xbmc
File: xbmc/settings/AdvancedSettings.cpp (C++)

Code before:
#include "utils/XMLUtils.h"
#include "utils/log.h"

#include <algorithm>
#include <climits>
#include <regex>
#include <string>
#include <vector>

using namespace ADDON;

namespace
{

bool validateVideoStackRegex(const CRegExp& regex)
{
  if (regex.GetCaptureTotal() != 4)
  {
    CLog::Log(LOGERROR, "Invalid video stack RE ({}). Must have exactly 4 captures.",
              regex.GetPattern());
    return false;
  }
  return true;
};

VECCREGEXP CompileRegexesFromXML(TiXmlElement* pFolderStacking)
{
  std::vector<std::string> patterns;
  CAdvancedSettings::GetCustomRegexps(pFolderStacking, patterns);
  return CompileRegexes(patterns);
}

} // unnamed namespace

void CAdvancedSettings::OnSettingsLoaded()
{
  const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();

  // load advanced settings
  Load(*profileManager);

  // default players?
  CLog::Log(LOGINFO, "Default Video Player: {}", m_videoDefaultPlayer);
  CLog::Log(LOGINFO, "Default Audio Player: {}", m_audioDefaultPlayer);

  // setup any logging...
  const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  if (settings->GetBool(CSettings::SETTING_DEBUG_SHOWLOGINFO))
  {
    m_logLevel = std::max(m_logLevelHint, LOG_LEVEL_DEBUG_FREEMEM);
    CLog::Log(LOGINFO, "Enabled debug logging due to GUI setting ({})", m_logLevel);

Review comment (suggestion):
```suggestion
std::vector<CRegExp> CompileRegexesFromXML(TiXmlElement* folderStacking)
```

Code after:
#include "utils/XMLUtils.h"
#include "utils/log.h"

#include <algorithm>
#include <climits>
#include <regex>
#include <string>
#include <vector>

using namespace ADDON;

namespace
{

bool ValidateVideoStackRegex(const CRegExp& regex)
{
  if (regex.GetCaptureTotal() != 4)
  {
    CLog::Log(LOGERROR, "Invalid video stack RE ({}). Must have exactly 4 captures.",
              regex.GetPattern());
    return false;
  }
  return true;
};

std::vector<CRegExp> CompileRegexesFromXML(TiXmlElement* folderStacking)
{
  std::vector<std::string> patterns;
  CAdvancedSettings::GetCustomRegexps(folderStacking, patterns);
  return CompileRegexes(patterns);
}

} // unnamed namespace

void CAdvancedSettings::OnSettingsLoaded()
{
  const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();

  // load advanced settings
  Load(*profileManager);

  // default players?
  CLog::Log(LOGINFO, "Default Video Player: {}", m_videoDefaultPlayer);
  CLog::Log(LOGINFO, "Default Audio Player: {}", m_audioDefaultPlayer);

  // setup any logging...
  const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
  if (settings->GetBool(CSettings::SETTING_DEBUG_SHOWLOGINFO))
  {
    m_logLevel = std::max(m_logLevelHint, LOG_LEVEL_DEBUG_FREEMEM);
    CLog::Log(LOGINFO, "Enabled debug logging due to GUI setting ({})", m_logLevel);
Repository: xbmc/xbmc
File: xbmc/cores/RetroPlayer/shaders/ShaderPresetFactory.cpp (C++)

Code before:
    if (bIsDisabled)
      UnregisterLoader(shaderAddon.get());
    else
      m_shaderAddons.try_emplace(addonId, std::move(shaderAddon));
  }

  // Look for new add-ons
  for (const AddonInfoPtr& shaderAddon : addonInfo)
  {
    const std::string& addonId = shaderAddon->ID();

    const bool bIsNew = (!m_shaderAddons.contains(addonId));
    if (!bIsNew)
      continue;

    const bool bIsFailed = (m_failedAddons.contains(addonId));
    if (bIsFailed)
      continue;

    auto addonPtr = std::make_unique<CShaderPresetAddon>(shaderAddon);

    if (addonPtr->CreateAddon())
    {
      for (const auto& extension : addonPtr->GetExtensions())
        RegisterLoader(addonPtr.get(), extension);
      m_shaderAddons.emplace(addonId, std::move(addonPtr));
    }
    else
    {
      m_failedAddons.try_emplace(addonId, std::move(addonPtr));
    }
  }
}


Review comment (suggestion):
A better fix is imo to change line 127 to `std::string addonId =`, not to remove `std::move` here.

Code after:
    if (bIsDisabled)
      UnregisterLoader(shaderAddon.get());
    else
      m_shaderAddons.try_emplace(addonId, std::move(shaderAddon));
  }

  // Look for new add-ons
  for (const AddonInfoPtr& shaderAddon : addonInfo)
  {
    std::string addonId = shaderAddon->ID();

    const bool bIsNew = (!m_shaderAddons.contains(addonId));
    if (!bIsNew)
      continue;

    const bool bIsFailed = (m_failedAddons.contains(addonId));
    if (bIsFailed)
      continue;

    auto addonPtr = std::make_unique<CShaderPresetAddon>(shaderAddon);

    if (addonPtr->CreateAddon())
    {
      for (const auto& extension : addonPtr->GetExtensions())
        RegisterLoader(addonPtr.get(), extension);
      m_shaderAddons.emplace(std::move(addonId), std::move(addonPtr));
    }
    else
    {
      m_failedAddons.try_emplace(std::move(addonId), std::move(addonPtr));
    }
  }
}
Repository: xbmc/xbmc
File: xbmc/cores/RetroPlayer/shaders/ShaderPresetFactory.cpp (C++)

Code before:
  }

  // Look for new add-ons
  for (const AddonInfoPtr& shaderAddon : addonInfo)
  {
    const std::string& addonId = shaderAddon->ID();

    const bool bIsNew = (!m_shaderAddons.contains(addonId));
    if (!bIsNew)
      continue;

    const bool bIsFailed = (m_failedAddons.contains(addonId));
    if (bIsFailed)
      continue;

    auto addonPtr = std::make_unique<CShaderPresetAddon>(shaderAddon);

    if (addonPtr->CreateAddon())
    {
      for (const auto& extension : addonPtr->GetExtensions())
        RegisterLoader(addonPtr.get(), extension);
      m_shaderAddons.emplace(addonId, std::move(addonPtr));
    }
    else
    {
      m_failedAddons.try_emplace(addonId, std::move(addonPtr));
    }
  }
}


Review comment (suggestion):
A better fix is imo to change line 127 to `std::string addonId =`, not to remove `std::move` here.

Code after:
  }

  // Look for new add-ons
  for (const AddonInfoPtr& shaderAddon : addonInfo)
  {
    std::string addonId = shaderAddon->ID();

    const bool bIsNew = (!m_shaderAddons.contains(addonId));
    if (!bIsNew)
      continue;

    const bool bIsFailed = (m_failedAddons.contains(addonId));
    if (bIsFailed)
      continue;

    auto addonPtr = std::make_unique<CShaderPresetAddon>(shaderAddon);

    if (addonPtr->CreateAddon())
    {
      for (const auto& extension : addonPtr->GetExtensions())
        RegisterLoader(addonPtr.get(), extension);
      m_shaderAddons.emplace(std::move(addonId), std::move(addonPtr));
    }
    else
    {
      m_failedAddons.try_emplace(std::move(addonId), std::move(addonPtr));
    }
  }
}
Repository: xbmc/xbmc
File: xbmc/cores/DllLoader/exports/emu_msvcrt.cpp (C++)

Code before:
    for (const SDirData& dir : vecDirsOpen)
    {
      if (dirp == (DIR*)&dir)
      {
        emulated = true;
        break;
      }
    }
    if (!emulated)
      return readdir(dirp); // local dir

    // dirp is actually a SDirData*
    SDirData* dirData = reinterpret_cast<SDirData*>(dirp);
    if (dirData->last_entry)
      free(dirData->last_entry);
    struct dirent *entry = NULL;
    entry = (dirent*) malloc(sizeof(*entry));
    if (dirData->curr_index < dirData->items.Size() + 2)
    { // simulate the '.' and '..' dir entries
      if (dirData->curr_index == 0)
        strncpy(entry->d_name, ".\0", 2);
      else if (dirData->curr_index == 1)
        strncpy(entry->d_name, "..\0", 3);
      else
      {
        strncpy(entry->d_name, dirData->items[dirData->curr_index - 2]->GetLabel().c_str(), sizeof(entry->d_name));
        entry->d_name[sizeof(entry->d_name)-1] = '\0'; // null-terminate any truncated paths
      }
      dirData->last_entry = entry;
      dirData->curr_index++;
      return entry;
    }
    free(entry);
    return NULL;
  }

  int dll_closedir(DIR *dirp)
  {
    bool emulated(false);
    for (const SDirData& dir : vecDirsOpen)
    {
      if (dirp == (DIR*)&dir)
      {
        emulated = true;
        break;
      }
    }
    if (!emulated)
      return closedir(dirp);

    SDirData* dirData = reinterpret_cast<SDirData*>(dirp);

Review comment (suggestion):
You can use `strncpy_s` to make sure not introduce unwanted behavior change

```suggestion
        strncpy_s(entry->d_name, sizeof(entry->d_name),
                  dirData->items[dirData->curr_index - 2]->GetLabel().c_str(),
                  sizeof(entry->d_name));
```

Code after:
    for (const SDirData& dir : vecDirsOpen)
    {
      if (dirp == (DIR*)&dir)
      {
        emulated = true;
        break;
      }
    }
    if (!emulated)
      return readdir(dirp); // local dir

    // dirp is actually a SDirData*
    SDirData* dirData = reinterpret_cast<SDirData*>(dirp);
    if (dirData->last_entry)
      free(dirData->last_entry);
    struct dirent *entry = NULL;
    entry = (dirent*) malloc(sizeof(*entry));
    if (dirData->curr_index < dirData->items.Size() + 2)
    { // simulate the '.' and '..' dir entries
      if (dirData->curr_index == 0)
        strncpy(entry->d_name, ".\0", 2);
      else if (dirData->curr_index == 1)
        strncpy(entry->d_name, "..\0", 3);
      else
      {
        snprintf(entry->d_name, sizeof(entry->d_name), "%s",
                 dirData->items[dirData->curr_index - 2]->GetLabel().c_str());
      }
      dirData->last_entry = entry;
      dirData->curr_index++;
      return entry;
    }
    free(entry);
    return NULL;
  }

  int dll_closedir(DIR *dirp)
  {
    bool emulated(false);
    for (const SDirData& dir : vecDirsOpen)
    {
      if (dirp == (DIR*)&dir)
      {
        emulated = true;
        break;
      }
    }
    if (!emulated)
      return closedir(dirp);

    SDirData* dirData = reinterpret_cast<SDirData*>(dirp);
Repository: xbmc/xbmc
File: xbmc/platform/posix/filesystem/SMBDirectory.cpp (C++)

Code before:
    bool hidden = false;

    if (StringUtils::StartsWith(strFile, "."))
      hidden = true;

    // only stat files that can give proper responses
    if (S_ISREG(st.st_mode) || bIsDir)
    {
      nstats++;
      // This is also present in stuct stat using S_IXOTH but given the potential for confusion
      // let's be explicit.
      hidden = hidden || fi->attrs & SMBC_DOS_MODE_HIDDEN;

      lTimeDate = st.st_mtime;
      if (lTimeDate == 0) // if modification date is missing, use create date
        lTimeDate = st.st_ctime;
      iSize = st.st_size;
    }

    KODI::TIME::FileTime fileTime, localTime;
    KODI::TIME::TimeTToFileTime(lTimeDate, &fileTime);
    KODI::TIME::FileTimeToLocalFileTime(&fileTime, &localTime);

    if (bIsDir)
    {
      CFileItemPtr pItem(new CFileItem(strFile));
      std::string path(strRoot);

      path = URIUtils::AddFileToFolder(path, fi->name);
      URIUtils::AddSlashAtEnd(path);
      pItem->SetPath(path);
      pItem->SetFolder(true);
      pItem->SetDateTime(localTime);
      if (hidden)
        pItem->SetProperty("file:hidden", true);
      items.Add(pItem);
    }
    else
    {
      CFileItemPtr pItem(new CFileItem(strFile));
      pItem->SetPath(strRoot + fi->name);
      pItem->SetFolder(false);
      pItem->SetSize(iSize);
      pItem->SetDateTime(localTime);
      if (hidden)
        pItem->SetProperty("file:hidden", true);
      items.Add(pItem);
    }
  }

  // No results from smbc_readdirplus2() suggests server or share browsing.

Review comment (suggestion):
Instead of the legacy typedef use the real type `std::make_shared<CFileItem>` and also drop `p` prefix

Code after:
      hidden = hidden || fi->attrs & SMBC_DOS_MODE_HIDDEN;

      timeDate = st.st_mtime;
      if (timeDate == 0) // if modification date is missing, use create date
        timeDate = st.st_ctime;
      size = st.st_size;
    }

    KODI::TIME::FileTime fileTime, localTime;
    KODI::TIME::TimeTToFileTime(timeDate, &fileTime);
    KODI::TIME::FileTimeToLocalFileTime(&fileTime, &localTime);

    const auto item = std::make_shared<CFileItem>(name);
    item->SetDateTime(localTime);
    if (hidden)
      item->SetProperty("file:hidden", true);
    if (isDir)
    {
      std::string path(strRoot);

      path = URIUtils::AddFileToFolder(path, name);
      URIUtils::AddSlashAtEnd(path);
      item->SetPath(path);
      item->SetFolder(true);
    }
    else
    {
      item->SetPath(strRoot + name);
      item->SetFolder(false);
      item->SetSize(size);
    }
    items.Add(item);
  }

  // No results from smbc_readdirplus2() suggests server or share browsing.
  // Use smbclient's legacy API for this.
  if (!atLeastOneEntry)
  {
    if (smbc_lseekdir(fd, 0) < 0)
    {
      CLog::LogF(LOGERROR, "Unable to seek directory : '{}'\nunix_err:'{:x}' error: '{}'",
                 CURL::GetRedacted(strAuth), errno, strerror(errno));
      return false;
    }

    struct smbc_dirent* dirent;
    while ((dirent = smbc_readdir(fd)))
    {
      if (dirent->smbc_type != SMBC_FILE_SHARE && dirent->smbc_type != SMBC_SERVER)
        continue;
Repository: xbmc/xbmc
File: xbmc/utils/URIUtils.cpp (C++)

Code before:
  {
    strChangedFile = strFile;
    strChangedFile += strNewExtension;
  }
  return strChangedFile;
}

std::string URIUtils::GetFileName(const CURL& url)
{
  return GetFileName(url.GetFileName());
}

/* returns a filename given an url */
/* handles both / and \, and options in urls*/
std::string URIUtils::GetFileName(const std::string& strFileNameAndPath)
{
  if(IsURL(strFileNameAndPath))
  {
    CURL url(strFileNameAndPath);
    return GetFileName(url.GetFileName());
  }

  int i = strFileNameAndPath.size() - 1;
  while (i >= 0)
  {
    const char& ch = strFileNameAndPath[i];
    // Only break on ':' if it's a drive separator for DOS (ie d:foo)
    if (ch == '/' || ch == '\\' || (ch == ':' && i == 1))
      break;
    else
      i--;
  }
  return strFileNameAndPath.substr(i + 1);
}

std::string URIUtils::GetFileOrFolderName(const std::string& path)
{
  std::string temp = path;

  char ch = path[path.size() - 1];
  if (ch == '/' || ch == '\\')
  {
    temp = path.substr(0, path.size() - 1);
  }

  return temp.substr(temp.find_last_of("/\\") + 1);
}

void URIUtils::Split(const std::string& strFileNameAndPath,
                     std::string& strPath, std::string& strFileName)
{

Review comment (performance):
Can you do

```c++
const char ch = strFileNameAndPath[i];
```

? 

We don't need dangling lifetime and optimizers like this better.

Code after:
  {
    strChangedFile = strFile;
    strChangedFile += strNewExtension;
  }
  return strChangedFile;
}

std::string URIUtils::GetFileName(const CURL& url)
{
  return GetFileName(url.GetFileName());
}

/* returns a filename given an url */
/* handles both / and \, and options in urls*/
std::string URIUtils::GetFileName(const std::string& strFileNameAndPath)
{
  if(IsURL(strFileNameAndPath))
  {
    CURL url(strFileNameAndPath);
    return GetFileName(url.GetFileName());
  }

  int i = strFileNameAndPath.size() - 1;
  while (i >= 0)
  {
    const char ch = strFileNameAndPath[i];
    // Only break on ':' if it's a drive separator for DOS (ie d:foo)
    if (ch == '/' || ch == '\\' || (ch == ':' && i == 1))
      break;
    else
      i--;
  }
  return strFileNameAndPath.substr(i + 1);
}

std::string URIUtils::GetFileOrFolderName(const std::string& path)
{
  std::string temp = path;

  char ch = path[path.size() - 1];
  if (ch == '/' || ch == '\\')
  {
    temp = path.substr(0, path.size() - 1);
  }

  return temp.substr(temp.find_last_of("/\\") + 1);
}

void URIUtils::Split(const std::string& strFileNameAndPath,
                     std::string& strPath, std::string& strFileName)
{
Repository: xbmc/xbmc
File: xbmc/filesystem/NFSDirectory.cpp (C++)

Code before:
#include <limits.h>

#include <nfsc/libnfs-raw-nfs.h>
#include <nfsc/libnfs.h>

#if defined(TARGET_WINDOWS)
#define S_IFLNK 0120000
#define S_ISBLK(m) (0)
#define S_ISSOCK(m) (0)
#define S_ISLNK(m) ((m & S_IFLNK) != 0)
#define S_ISCHR(m) ((m & _S_IFCHR) != 0)
#define S_ISDIR(m) ((m & _S_IFDIR) != 0)
#define S_ISFIFO(m) ((m & _S_IFIFO) != 0)
#define S_ISREG(m) ((m & _S_IFREG) != 0)
#endif

namespace
{

KODI::TIME::FileTime GetDirEntryTime(struct nfsdirent* dirent)
{
  // if modification date is missing, use create date
  const int64_t lTimeDate =
      (dirent->mtime.tv_sec == 0) ? dirent->ctime.tv_sec : dirent->mtime.tv_sec;

  KODI::TIME::FileTime fileTime, localTime;
  long long ll = lTimeDate & 0xffffffff;
  ll *= 10000000ll;
  ll += 116444736000000000ll;
  fileTime.lowDateTime = (DWORD)(ll & 0xffffffff);
  fileTime.highDateTime = (DWORD)(ll >> 32);
  KODI::TIME::FileTimeToLocalFileTime(&fileTime, &localTime);

  return localTime;
}

} // Unnamed namespace

CNFSDirectory::CNFSDirectory(void)
{
  gNfsConnection.AddActiveConnection();
}

CNFSDirectory::~CNFSDirectory(void)
{
  gNfsConnection.AddIdleConnection();
}

bool CNFSDirectory::GetDirectoryFromExportList(const std::string& strPath, CFileItemList &items)
{
  CURL url(strPath);

Review comment (suggestion):
Since this code is touched, please follow code guidelines: one variable per line (https://github.com/xbmc/xbmc/blob/master/docs/CODE_GUIDELINES.md#52-multiple-declarations).

And better initialize structs:

```c++
KODI::TIME::FileTime fileTime{};
KODI::TIME::FileTime localTime{};
```

Code after:
#include <nfsc/libnfs-raw-nfs.h>
#include <nfsc/libnfs.h>

#if defined(TARGET_WINDOWS)
#define S_IFLNK 0120000
#define S_ISBLK(m) (0)
#define S_ISSOCK(m) (0)
#define S_ISLNK(m) ((m & S_IFLNK) != 0)
#define S_ISCHR(m) ((m & _S_IFCHR) != 0)
#define S_ISDIR(m) ((m & _S_IFDIR) != 0)
#define S_ISFIFO(m) ((m & _S_IFIFO) != 0)
#define S_ISREG(m) ((m & _S_IFREG) != 0)
#endif

namespace
{

KODI::TIME::FileTime GetDirEntryTime(struct nfsdirent* dirent)
{
  // if modification date is missing, use create date
  const int64_t timeDate =
      (dirent->mtime.tv_sec == 0) ? dirent->ctime.tv_sec : dirent->mtime.tv_sec;

  long long ll = timeDate & 0xffffffff;
  ll *= 10000000ll;
  ll += 116444736000000000ll;

  KODI::TIME::FileTime fileTime{};
  fileTime.lowDateTime = static_cast<DWORD>(ll & 0xffffffff);
  fileTime.highDateTime = static_cast<DWORD>(ll >> 32);

  KODI::TIME::FileTime localTime{};
  KODI::TIME::FileTimeToLocalFileTime(&fileTime, &localTime);

  return localTime;
}

} // Unnamed namespace

CNFSDirectory::CNFSDirectory(void)
{
  gNfsConnection.AddActiveConnection();
}

CNFSDirectory::~CNFSDirectory(void)
{
  gNfsConnection.AddIdleConnection();
}

std::vector<CFileItemPtr> CNFSDirectory::GetDirectoryFromExportList(const CURL& inputURL)
{
Repository: xbmc/xbmc
File: xbmc/filesystem/NFSDirectory.cpp (C++)

Code before:
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#ifdef TARGET_WINDOWS
#include <mutex>

#include <sys\stat.h>
#endif

#include "FileItem.h"
#include "FileItemList.h"
#include "NFSDirectory.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "utils/XTimeUtils.h"
#include "utils/log.h"

#ifdef TARGET_WINDOWS
#include <sys\stat.h>
#endif

using namespace XFILE;
#include <algorithm>
#include <limits.h>

#include <nfsc/libnfs-raw-nfs.h>
#include <nfsc/libnfs.h>

#if defined(TARGET_WINDOWS)
#define S_IFLNK 0120000
#define S_ISBLK(m) (0)
#define S_ISSOCK(m) (0)
#define S_ISLNK(m) ((m & S_IFLNK) != 0)
#define S_ISCHR(m) ((m & _S_IFCHR) != 0)
#define S_ISDIR(m) ((m & _S_IFDIR) != 0)
#define S_ISFIFO(m) ((m & _S_IFIFO) != 0)
#define S_ISREG(m) ((m & _S_IFREG) != 0)
#endif

namespace
{

KODI::TIME::FileTime GetDirEntryTime(struct nfsdirent* dirent)
{
  // if modification date is missing, use create date
  const int64_t timeDate =
      (dirent->mtime.tv_sec == 0) ? dirent->ctime.tv_sec : dirent->mtime.tv_sec;


Review comment (bug):
This header is still necessary?

Also `#include "utils/StringUtils.h"` can be removed now

Unrelated, but previous Windows Jenkins failures was because missing `<array>` header (not necessary now with latest force push). Anyway seems better squash commits to avoid problems.


Code after:
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#ifdef TARGET_WINDOWS
#include <mutex>

#include <sys\stat.h>
#endif

#include "FileItem.h"
#include "FileItemList.h"
#include "NFSDirectory.h"
#include "utils/URIUtils.h"
#include "utils/XTimeUtils.h"
#include "utils/log.h"

#ifdef TARGET_WINDOWS
#include <sys\stat.h>
#endif

using namespace XFILE;
#include <limits.h>

#include <nfsc/libnfs-raw-nfs.h>
#include <nfsc/libnfs.h>

#if defined(TARGET_WINDOWS)
#define S_IFLNK 0120000
#define S_ISBLK(m) (0)
#define S_ISSOCK(m) (0)
#define S_ISLNK(m) ((m & S_IFLNK) != 0)
#define S_ISCHR(m) ((m & _S_IFCHR) != 0)
#define S_ISDIR(m) ((m & _S_IFDIR) != 0)
#define S_ISFIFO(m) ((m & _S_IFIFO) != 0)
#define S_ISREG(m) ((m & _S_IFREG) != 0)
#endif

namespace
{

KODI::TIME::FileTime GetDirEntryTime(struct nfsdirent* dirent)
{
  // if modification date is missing, use create date
  const int64_t timeDate =
      (dirent->mtime.tv_sec == 0) ? dirent->ctime.tv_sec : dirent->mtime.tv_sec;

  long long ll = timeDate & 0xffffffff;
  ll *= 10000000ll;
Repository: xbmc/xbmc
File: xbmc/FileItemList.cpp (C++)

Code before:

void CFileItemList::Clear()
{
  std::unique_lock lock(m_lock);

  ClearItems();
  m_sortDescription.sortBy = SortByNone;
  m_sortDescription.sortOrder = SortOrderNone;
  m_sortDescription.sortAttributes = SortAttributeNone;
  m_sortIgnoreFolders = false;
  m_cacheToDisc = CacheType::IF_SLOW;
  m_sortDetails.clear();
  m_replaceListing = false;
  m_content.clear();
}

void CFileItemList::ClearItems()
{
  std::unique_lock lock(m_lock);
  // make sure we free the memory of the items (these are GUIControls which may have allocated resources)
  FreeMemory();
  std::ranges::for_each(m_items, [](const auto& item) { item->FreeMemory(); });
  m_items.clear();
  m_map.clear();
}

void CFileItemList::Add(CFileItemPtr pItem)
{
  std::unique_lock lock(m_lock);
  if (m_fastLookup)
  {
    m_map.try_emplace(m_ignoreURLOptions ? pItem->GetURL().GetWithoutOptions() : pItem->GetPath(),
                      pItem);
  }
  m_items.emplace_back(std::move(pItem));
}

void CFileItemList::Add(CFileItem&& item)
{
  std::unique_lock lock(m_lock);
  auto ptr = std::make_shared<CFileItem>(std::move(item));
  if (m_fastLookup)
  {
    m_map.try_emplace(m_ignoreURLOptions ? ptr->GetURL().GetWithoutOptions() : ptr->GetPath(), ptr);
  }
  m_items.emplace_back(std::move(ptr));
}

void CFileItemList::AddFront(const CFileItemPtr& pItem, int itemPosition)
{
  std::unique_lock lock(m_lock);

Review comment (performance):
Why remove the GetURL() from the previous code? It looked like the URL was cached, so even if the CURL was created for this function and there is no immediate saving, another caller later on may.

Code after:

  ClearItems();
  m_sortDescription.sortBy = SortByNone;
  m_sortDescription.sortOrder = SortOrderNone;
  m_sortDescription.sortAttributes = SortAttributeNone;
  m_sortIgnoreFolders = false;
  m_cacheToDisc = CacheType::IF_SLOW;
  m_sortDetails.clear();
  m_replaceListing = false;
  m_content.clear();
}

void CFileItemList::ClearItems()
{
  std::unique_lock lock(m_lock);
  // make sure we free the memory of the items (these are GUIControls which may have allocated resources)
  FreeMemory();
  std::ranges::for_each(m_items, [](const auto& item) { item->FreeMemory(); });
  m_items.clear();
  m_map.clear();
}

void CFileItemList::AddFastLookupItem(const CFileItemPtr& item)
{
  m_map.try_emplace(
      m_ignoreURLOptions ? CURL(item->GetPath()).GetWithoutOptions() : item->GetPath(), item);
}

void CFileItemList::AddFastLookupItems(const std::vector<CFileItemPtr>& items)
{
  for (const auto& item : items)
    AddFastLookupItem(item);
}

void CFileItemList::Add(CFileItemPtr pItem)
{
  std::unique_lock lock(m_lock);
  if (m_fastLookup)
    AddFastLookupItem(pItem);
  m_items.emplace_back(std::move(pItem));
}

void CFileItemList::Add(CFileItem&& item)
{
  std::unique_lock lock(m_lock);
  auto ptr = std::make_shared<CFileItem>(std::move(item));
  if (m_fastLookup)
    AddFastLookupItem(ptr);
  m_items.emplace_back(std::move(ptr));
}