Repository: xbmc/xbmc
File: xbmc/platform/win32/filesystem/Win32SMBDirectory.cpp (C++)

Code before:
  {
    std::wstring itemNameW(findData.cFileName);
    if (itemNameW == L"." || itemNameW == L".." || itemNameW.empty())
      continue;

    std::string itemName;
    if (!g_charsetConverter.wToUTF8(itemNameW, itemName, true) || itemName.empty())
    {
      CLog::LogF(LOGERROR, "Can't convert wide string item name to UTF-8");
      continue;
    }

    bool isDir = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
    bool isHidden =
        (findData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0 ||
        itemName.front() == '.'; // mark files starting from dot as hidden

    std::string itemPath(pathWithSlash + itemName);
    if (isDir)
      itemPath += '/';

    // calculation of size and date costs a little on win32
    // so DIR_FLAG_NO_FILE_INFO flag is ignored
    CFileItemPtr& item = fileItems.emplace_back(std::make_shared<CFileItem>(itemName));
    item->SetFolder(isDir);
    item->SetPath(itemPath);
    item->SetDateTime(GetEntryTime(item, findData));
    if (!isDir)
      item->SetSize(GetEntrySize(findData));
    if (isHidden)
      item->SetProperty("file:hidden", true);

  } while (FindNextFileW(hSearch, &findData));
  items.AddItems(std::move(fileItems));

  FindClose(hSearch);

  return true;
}

bool CWin32SMBDirectory::Create(const CURL& url)
{
  return RealCreate(url, true);
}

bool CWin32SMBDirectory::RealCreate(const CURL& url, bool tryToConnect)
{
  assert(url.IsProtocol("smb"));
  if (url.GetHostName().empty() || url.GetShareName().empty() || url.GetFileName() == url.GetShareName())
    return false; // can't create new hosts or shares


Review comment (suggestion):
Since you're trying to eliminate copies, I think there is an opportunity here to move the item path. Current signature takes a string_view. there will be at least a copy inside SetPath to go string_view > string.

Code after:
      pItem->SetDateTime(localTime);
    else
    {
      CDateTime dt{pItem->GetDateTime()};
      dt.SetValid(false);
      pItem->SetDateTime(dt);
    }
    if (!pItem->IsFolder())
      pItem->SetSize((__int64(findData.nFileSizeHigh) << 32) + findData.nFileSizeLow);

    items.Add(pItem);
  } while (FindNextFileW(hSearch, &findData));

  FindClose(hSearch);

  return true;
}

bool CWin32SMBDirectory::Create(const CURL& url)
{
  return RealCreate(url, true);
}

bool CWin32SMBDirectory::RealCreate(const CURL& url, bool tryToConnect)
{
  assert(url.IsProtocol("smb"));
  if (url.GetHostName().empty() || url.GetShareName().empty() || url.GetFileName() == url.GetShareName())
    return false; // can't create new hosts or shares

  std::wstring nameW(prepareWin32SMBDirectoryName(url));
  if (nameW.empty())
    return false;

  if (!CreateDirectoryW(nameW.c_str(), NULL))
  {
    if (GetLastError() == ERROR_ALREADY_EXISTS)
      return RealExists(url, false); // is it file or directory?
    else
    {
      if (tryToConnect && worthTryToConnect(GetLastError()))
      {
        CURL authUrl(url);
        if (ConnectAndAuthenticate(authUrl))
          return RealCreate(authUrl, false);
      }
      return false;
    }
  }

  // if directory name starts from dot, make it hidden
  const size_t lastSlashPos = nameW.rfind(L'\\');