Skip to content

Commit 1cafe04

Browse files
committed
less string copying
1 parent ecbf976 commit 1cafe04

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/SongControl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ namespace SongControl {
192192
} else songManager.resetTowerRepeatCount();
193193

194194
const std::filesystem::path& playlistFilePath = geode::Mod::get()->getSettingValue<std::filesystem::path>("playlistFile");
195-
if (playlistFilePath.string().empty() || playlistFilePath.extension() != ".txt" || !Utils::notFavoritesNorBlacklist(playlistFilePath)) {
195+
if (const std::string& normalizedPlaylistPath = Utils::toNormalizedString(playlistFilePath); normalizedPlaylistPath.empty() || Utils::toNormalizedString(playlistFilePath.extension()) != ".txt" || !Utils::notFavoritesNorBlacklist(playlistFilePath)) {
196196
return geode::Notification::create(
197197
"Invalid text file selected as your MLR playlist file!",
198198
geode::NotificationIcon::Error, 5.f

src/Utils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ void Utils::addButton(const std::string& name, const cocos2d::SEL_MenuHandler fu
637637
if (menu->getLayout()) menu->updateLayout();
638638
}
639639

640-
bool Utils::notFavoritesNorBlacklist(std::filesystem::path filePath) {
640+
bool Utils::notFavoritesNorBlacklist(const std::filesystem::path& filePath) {
641641
const std::string& fileString = Utils::toNormalizedString(filePath);
642642
return !geode::utils::string::endsWith(fileString, "favorites.txt") && !geode::utils::string::endsWith(fileString, "blacklist.txt");
643643
}
@@ -665,7 +665,7 @@ std::string Utils::generatePlatformWarning() {
665665
return fmt::format("This playlist file was created using {}. ***__YOU REALLY SHOULD NOT BE SHARING THIS FILE WITH OTHERS__***, but if you have to, only share this file with other MLR users on {}.", platform, platform);
666666
}
667667

668-
void Utils::writeToFile(const std::string& toWriteToFile, std::filesystem::path fileForWriting) {
668+
void Utils::writeToFile(const std::string& toWriteToFile, const std::filesystem::path& fileForWriting) {
669669
if (!std::filesystem::exists(fileForWriting) && Utils::notFavoritesNorBlacklist(fileForWriting)) {
670670
const std::string& platformWarning = Utils::generatePlatformWarning();
671671
const std::string& playlistSpecificIntro = fmt::format(R"(# Welcome to a Menu Loop Randomizer playlist file!
@@ -706,12 +706,12 @@ platformWarning, platformWarning);
706706
auto result = geode::utils::file::writeString(fileForWriting, playlistSpecificIntro);
707707
if (result.isErr()) return geode::log::error("Error writing to {}", fileForWriting);
708708
} else if (!std::filesystem::exists(fileForWriting)) return geode::log::info("error finding {}!", fileForWriting);
709-
std::string toWriteToFileFinal = toWriteToFile;
710-
if (geode::utils::string::endsWith(toWriteToFileFinal, " [MLR] #") && SongManager::get().getSawbladeCustomSongsFolder()) {
711-
toWriteToFileFinal = geode::utils::string::replace(toWriteToFileFinal, " [MLR] #", " (Note: This was added to this file while using a non-vanilla custom songs folder location.) [MLR] #");
712-
}
713709
std::ofstream fileOutput;
714710
fileOutput.open(fileForWriting, std::ios_base::app);
715-
fileOutput << std::endl << toWriteToFileFinal;
711+
if (geode::utils::string::endsWith(toWriteToFile, " [MLR] #") && SongManager::get().getSawbladeCustomSongsFolder()) {
712+
fileOutput << std::endl << geode::utils::string::replace(toWriteToFile, " [MLR] #", " (Note: This was added to this file while using a non-vanilla custom songs folder location.) [MLR] #");
713+
} else {
714+
fileOutput << std::endl << toWriteToFile;
715+
}
716716
fileOutput.close();
717717
}

src/Utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class Utils {
3737
static void removeCardRemotely(cocos2d::CCNode* card = Utils::findCardRemotely());
3838
static void queueUpdateSCMLabel();
3939
static void addButton(const std::string& name, const cocos2d::SEL_MenuHandler function, cocos2d::CCMenu* menu, cocos2d::CCNode* target);
40-
static bool notFavoritesNorBlacklist(std::filesystem::path fileForWriting);
40+
static bool notFavoritesNorBlacklist(const std::filesystem::path& fileForWriting);
4141
static std::string getPlatform();
4242
static std::string generatePlatformWarning();
43-
static void writeToFile(const std::string& toWriteToFile, std::filesystem::path fileForWriting);
43+
static void writeToFile(const std::string& toWriteToFile, const std::filesystem::path& fileForWriting);
4444
};

0 commit comments

Comments
 (0)