Skip to content

Commit

Permalink
save_playlist: pass name as std::string
Browse files Browse the repository at this point in the history
A std::string is being allocated anyway.  This eliminates some
Utf8ToLocaleZ overhead.
  • Loading branch information
MaxKellermann committed Sep 6, 2024
1 parent 1025a2c commit af80c6d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/EditPlaylistPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ EditPlaylistPage::OnCommand(struct mpdclient &c, Command cmd)
return HandleDelete(c);

case Command::SAVE_PLAYLIST:
//playlist_save(screen, c, nullptr);
//playlist_save(screen, c);
// TODO
return true;

Expand Down
6 changes: 2 additions & 4 deletions src/FileBrowserPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,8 @@ FileBrowserPage::HandleSave(struct mpdclient &c) noexcept
}
}

if(defaultname)
playlist_save(screen, c, Utf8ToLocaleZ{defaultname}.c_str());
else
playlist_save(screen, c, nullptr);
playlist_save(screen, c,
defaultname != nullptr ? Utf8ToLocale{defaultname}.str() : std::string{});
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/QueuePage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ QueuePage::OnCommand(struct mpdclient &c, Command cmd)
}

case Command::SAVE_PLAYLIST:
playlist_save(screen, c, nullptr);
playlist_save(screen, c);
return true;

case Command::ADD:
Expand Down
10 changes: 4 additions & 6 deletions src/save_playlist.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ PlaylistNameCompletion::Post([[maybe_unused]] std::string_view value,

#endif


int
playlist_save(ScreenManager &screen, struct mpdclient &c,
const char *name) noexcept
std::string filename) noexcept
{
std::string filename;

if (name == nullptr) {
if (filename.empty()) {
#ifdef NCMPC_MINI
Completion *completion = nullptr;
#else
Expand All @@ -74,8 +73,7 @@ playlist_save(ScreenManager &screen, struct mpdclient &c,
completion);
if (filename.empty())
return -1;
} else
filename = name;
}

/* send save command to mpd */

Expand Down
4 changes: 3 additions & 1 deletion src/save_playlist.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

#pragma once

#include <string>

class ScreenManager;
struct mpdclient;

int
playlist_save(ScreenManager &screen, struct mpdclient &c,
const char *name) noexcept;
std::string name={}) noexcept;

0 comments on commit af80c6d

Please sign in to comment.