Skip to content

Commit

Permalink
clang-tidy: convert 'endl' to '\n' for performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
sa666666 committed Nov 16, 2023
1 parent 27c3e09 commit 7818787
Show file tree
Hide file tree
Showing 95 changed files with 514 additions and 543 deletions.
2 changes: 1 addition & 1 deletion src/cheat/CheatManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void CheatManager::saveCheatDatabase()

stringstream out;
for(const auto& [md5, cheat]: myCheatMap)
out << "\"" << md5 << "\" " << "\"" << cheat << "\"" << endl;
out << "\"" << md5 << "\" " << "\"" << cheat << "\"\n";

try { myOSystem.cheatFile().write(out); }
catch(...) { return; }
Expand Down
3 changes: 2 additions & 1 deletion src/common/EventHandlerSDL2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ EventHandlerSDL2::EventHandlerSDL2(OSystem& osystem)
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
{
ostringstream buf;
buf << "ERROR: Couldn't initialize SDL joystick support: " << SDL_GetError() << endl;
buf << "ERROR: Couldn't initialize SDL joystick support: "
<< SDL_GetError() << '\n';
Logger::error(buf.str());
}
Logger::debug("EventHandlerSDL2::EventHandlerSDL2 SDL_INIT_JOYSTICK");
Expand Down
12 changes: 6 additions & 6 deletions src/common/FBBackendSDL2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ bool FBBackendSDL2::adaptRefreshRate(Int32 displayIndex,
// cerr << "required (" << currentRefreshRate << " Hz -> " << adaptedSdlMode.refresh_rate << " Hz)";
//else
// cerr << "not required/possible";
//cerr << endl;
//cerr << '\n';

// Only change if the display supports a better refresh rate
return adapt;
Expand Down Expand Up @@ -425,7 +425,7 @@ bool FBBackendSDL2::createRenderer()

if(recreate)
{
//cerr << "Create new renderer for buffer type #" << int(myBufferType) << endl;
//cerr << "Create new renderer for buffer type #" << int(myBufferType) << '\n';
if(myRenderer)
SDL_DestroyRenderer(myRenderer);

Expand Down Expand Up @@ -471,18 +471,18 @@ string FBBackendSDL2::about() const
ASSERT_MAIN_THREAD;

ostringstream out;
out << "Video system: " << SDL_GetCurrentVideoDriver() << endl;
out << "Video system: " << SDL_GetCurrentVideoDriver() << '\n';
SDL_RendererInfo info;
if(SDL_GetRendererInfo(myRenderer, &info) >= 0)
{
out << " Renderer: " << info.name << endl;
out << " Renderer: " << info.name << '\n';
if(info.max_texture_width > 0 && info.max_texture_height > 0)
out << " Max texture: " << info.max_texture_width << "x"
<< info.max_texture_height << endl;
<< info.max_texture_height << '\n';
out << " Flags: "
<< ((info.flags & SDL_RENDERER_PRESENTVSYNC) ? "+" : "-") << "vsync, "
<< ((info.flags & SDL_RENDERER_ACCELERATED) ? "+" : "-") << "accel"
<< endl;
<< '\n';
}
return out.str();
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/FBSurfaceSDL2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ FBSurfaceSDL2::FBSurfaceSDL2(FBBackendSDL2& backend,
: myBackend{backend},
myInterpolationMode{inter}
{
//cerr << width << " x " << height << endl;
//cerr << width << " x " << height << '\n';
createSurface(width, height, staticData);
}

Expand Down
6 changes: 3 additions & 3 deletions src/common/FSNodeZIP.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FSNodeZIP::FSNodeZIP(string_view p)
#endif
}

// cerr << " => p: " << p << endl;
// cerr << " => p: " << p << '\n';

// Open file at least once to initialize the virtual file count
try
Expand Down Expand Up @@ -104,7 +104,7 @@ FSNodeZIP::FSNodeZIP(string_view p)

setFlags(_zipFile, _virtualPath, _realNode);
// cerr << "==============================================================\n";
// cerr << _name << ", file: " << _isFile << ", dir: " << _isDirectory << endl << endl;
// cerr << _name << ", file: " << _isFile << ", dir: " << _isDirectory << "\n\n";
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand All @@ -114,7 +114,7 @@ FSNodeZIP::FSNodeZIP(const string& zipfile, const string& virtualpath,
_isDirectory{isdir},
_isFile{!isdir}
{
// cerr << "=> c'tor 2: " << zipfile << ", " << virtualpath << ", " << isdir << endl;
// cerr << "=> c'tor 2: " << zipfile << ", " << virtualpath << ", " << isdir << '\n';
setFlags(zipfile, virtualpath, realnode);
}

Expand Down
12 changes: 6 additions & 6 deletions src/common/FSNodeZIP.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ class FSNodeZIP : public AbstractFSNode

friend ostream& operator<<(ostream& os, const FSNodeZIP& node)
{
os << "_zipFile: " << node._zipFile << endl
<< "_virtualPath: " << node._virtualPath << endl
<< "_name: " << node._name << endl
<< "_path: " << node._path << endl
<< "_size: " << node._size << endl
<< "_shortPath: " << node._shortPath << endl;
os << "_zipFile: " << node._zipFile << '\n'
<< "_virtualPath: " << node._virtualPath << '\n'
<< "_name: " << node._name << '\n'
<< "_path: " << node._path << '\n'
<< "_size: " << node._size << '\n'
<< "_shortPath: " << node._shortPath << '\n';
return os;
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/Logger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ void Logger::logMessage(string_view message, Level level)

if(level == Logger::Level::ERR)
{
cout << message << endl << std::flush;
cout << message << '\n' << std::flush;
myLogMessages += message;
myLogMessages += "\n";
}
else if(static_cast<int>(level) <= myLogLevel ||
level == Logger::Level::ALWAYS)
{
if(myLogToConsole)
cout << message << endl << std::flush;
cout << message << '\n' << std::flush;
myLogMessages += message;
myLogMessages += "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/MouseControl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ MouseControl::MouseControl(Console& console, string_view mode)

#if 0
for(const auto& m: myModeList)
cerr << m << endl;
cerr << m << '\n';
#endif
}

Expand Down
26 changes: 13 additions & 13 deletions src/common/PJoystickHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ void PhysicalJoystickHandler::addToDatabase(const PhysicalJoystickPtr& stick)
}

ostringstream buf;
buf << "Added joystick " << stick->ID << ":" << endl
<< " " << stick->about() << endl;
buf << "Added joystick " << stick->ID << ":\n"
<< " " << stick->about() << '\n';
Logger::info(buf.str());
}

Expand All @@ -194,8 +194,8 @@ bool PhysicalJoystickHandler::remove(int id)
if(it != myDatabase.end() && it->second.joy == stick)
{
ostringstream buf;
buf << "Removed joystick " << mySticks[id]->ID << ":" << endl
<< " " << mySticks[id]->about() << endl;
buf << "Removed joystick " << mySticks[id]->ID << ":\n"
<< " " << mySticks[id]->about() << '\n';
Logger::info(buf.str());

// Remove joystick, but remember mapping
Expand Down Expand Up @@ -263,8 +263,8 @@ bool PhysicalJoystickHandler::mapStelladaptors(string_view saport, int ID)
{
// Erase a previously added Stelladapter with a higher ID
ostringstream buf;
buf << "Erased joystick " << _stick->ID << ":" << endl
<< " " << _stick->about() << endl;
buf << "Erased joystick " << _stick->ID << ":\n"
<< " " << _stick->about() << '\n';
Logger::info(buf.str());

_stick->name.erase(pos);
Expand Down Expand Up @@ -1105,17 +1105,17 @@ PhysicalJoystickHandler::MinStrickInfoList PhysicalJoystickHandler::minStickList
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ostream& operator<<(ostream& os, const PhysicalJoystickHandler& jh)
{
os << "---------------------------------------------------------" << endl
<< "joy database:" << endl;
os << "---------------------------------------------------------\n"
<< "joy database:\n";
for(const auto& [_name, _info]: jh.myDatabase)
os << _name << endl << _info << endl << endl;
os << _name << '\n' << _info << '\n\n';

os << "---------------------" << endl
<< "joy active:" << endl;
os << "---------------------\n"
<< "joy active:\n";
for(const auto& [_id, _joyptr]: jh.mySticks)
os << _id << ": " << *_joyptr << endl;
os << _id << ": " << *_joyptr << '\n';
os << "---------------------------------------------------------"
<< endl << endl << endl;
<< '\n\n\n';

return os;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/PJoystickHandler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PhysicalJoystickHandler
PhysicalJoystickPtr joy;

friend ostream& operator<<(ostream& os, const StickInfo& si) {
os << " joy: " << si.joy << endl << " map: " << si.mapping;
os << " joy: " << si.joy << "\n map: " << si.mapping;
return os;
}
};
Expand Down
40 changes: 20 additions & 20 deletions src/common/SoundSDL2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ SoundSDL2::SoundSDL2(OSystem& osystem, AudioSettings& audioSettings)
{
ostringstream buf;

buf << "WARNING: Failed to initialize SDL audio system! " << endl
<< " " << SDL_GetError() << endl;
buf << "WARNING: Failed to initialize SDL audio system! \n"
<< " " << SDL_GetError() << '\n';
Logger::error(buf.str());
return;
}
Expand Down Expand Up @@ -126,8 +126,8 @@ bool SoundSDL2::openDevice()
{
ostringstream buf;

buf << "WARNING: Couldn't open SDL audio device! " << endl
<< " " << SDL_GetError() << endl;
buf << "WARNING: Couldn't open SDL audio device! \n"
<< " " << SDL_GetError() << '\n';
Logger::error(buf.str());

return myIsInitializedFlag = false;
Expand Down Expand Up @@ -260,51 +260,51 @@ void SoundSDL2::adjustVolume(int direction)
string SoundSDL2::about() const
{
ostringstream buf;
buf << "Sound enabled:" << endl
<< " Volume: " << myAudioSettings.volume() << "%" << endl
<< " Device: " << myDevices.at(myDeviceId).first << endl
buf << "Sound enabled:\n"
<< " Volume: " << myAudioSettings.volume() << "%\n"
<< " Device: " << myDevices.at(myDeviceId).first << '\n'
<< " Channels: " << static_cast<uInt32>(myHardwareSpec.channels)
<< (myAudioQueue->isStereo() ? " (Stereo)" : " (Mono)") << endl
<< (myAudioQueue->isStereo() ? " (Stereo)" : " (Mono)") << '\n'
<< " Preset: ";
switch(myAudioSettings.preset())
{
case AudioSettings::Preset::custom:
buf << "Custom" << endl;
buf << "Custom\n";
break;
case AudioSettings::Preset::lowQualityMediumLag:
buf << "Low quality, medium lag" << endl;
buf << "Low quality, medium lag\n";
break;
case AudioSettings::Preset::highQualityMediumLag:
buf << "High quality, medium lag" << endl;
buf << "High quality, medium lag\n";
break;
case AudioSettings::Preset::highQualityLowLag:
buf << "High quality, low lag" << endl;
buf << "High quality, low lag\n";
break;
case AudioSettings::Preset::ultraQualityMinimalLag:
buf << "Ultra quality, minimal lag" << endl;
buf << "Ultra quality, minimal lag\n";
break;
}
buf << " Fragment size: " << static_cast<uInt32>(myHardwareSpec.samples)
<< " bytes" << endl
<< " bytes\n"
<< " Sample rate: " << static_cast<uInt32>(myHardwareSpec.freq)
<< " Hz" << endl;
<< " Hz\n";
buf << " Resampling: ";
switch(myAudioSettings.resamplingQuality())
{
case AudioSettings::ResamplingQuality::nearestNeightbour:
buf << "Quality 1, nearest neighbor" << endl;
buf << "Quality 1, nearest neighbor\n";
break;
case AudioSettings::ResamplingQuality::lanczos_2:
buf << "Quality 2, Lanczos (a = 2)" << endl;
buf << "Quality 2, Lanczos (a = 2)\n";
break;
case AudioSettings::ResamplingQuality::lanczos_3:
buf << "Quality 3, Lanczos (a = 3)" << endl;
buf << "Quality 3, Lanczos (a = 3)\n";
break;
}
buf << " Headroom: " << std::fixed << std::setprecision(1)
<< (0.5 * myAudioSettings.headroom()) << " frames" << endl
<< (0.5 * myAudioSettings.headroom()) << " frames\n"
<< " Buffer size: " << std::fixed << std::setprecision(1)
<< (0.5 * myAudioSettings.bufferSize()) << " frames" << endl;
<< (0.5 * myAudioSettings.bufferSize()) << " frames\n";
return buf.str();
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/StateManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ bool StateManager::loadState(Serializer& in)
}
catch(...)
{
cerr << "ERROR: StateManager::loadState(Serializer&)" << endl;
cerr << "ERROR: StateManager::loadState(Serializer&)\n";
}
return false;
}
Expand All @@ -366,7 +366,7 @@ bool StateManager::saveState(Serializer& out)
}
catch(...)
{
cerr << "ERROR: StateManager::saveState(Serializer&)" << endl;
cerr << "ERROR: StateManager::saveState(Serializer&)\n";
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/ThreadDebugging.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ThreadDebuggingHelper& ThreadDebuggingHelper::instance()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ThreadDebuggingHelper::fail(const string& message)
{
cerr << message << endl;
cerr << message << '\n';

throw runtime_error(message);
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/ZipHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ void ZipHandler::addToCache()
cerr << "\nCACHE contents:\n";
for(cachenum = 0; cachenum < myZipCache.size(); ++cachenum)
if(myZipCache[cachenum] != nullptr)
cerr << " " << cachenum << " : " << myZipCache[cachenum]->filename << endl;
cerr << endl;
cerr << " " << cachenum << " : " << myZipCache[cachenum]->filename << '\n';
cerr << '\n';
#endif
}

Expand Down
1 change: 0 additions & 1 deletion src/common/bspf.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ using uInt64 = uint64_t;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::string;
using std::string_view;
using std::istream;
Expand Down
16 changes: 8 additions & 8 deletions src/common/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void parseCommandLine(int ac, const char* const av[],

if(++i >= ac)
{
cerr << "Missing argument for '" << key << "'" << endl;
cerr << "Missing argument for '" << key << "'\n";
continue;
}
if(key == "basedir" || key == "break")
Expand All @@ -127,12 +127,12 @@ void parseCommandLine(int ac, const char* const av[],
}

#if 0
cout << "Global opts:" << endl;
cout << "Global opts:\n";
for(const auto& [key, value]: globalOpts)
cout << " -> " << key << ": " << value << endl;
cout << "Local opts:" << endl;
cout << " -> " << key << ": " << value << '\n';
cout << "Local opts:\n";
for(const auto& [key, value]: localOpts)
cout << " -> " << key << ": " << value << endl;
cout << " -> " << key << ": " << value << '\n';
#endif
}

Expand Down Expand Up @@ -180,15 +180,15 @@ void attachConsole()
SetConsoleCursorPosition(hConsole, pos);
}
else
cout << endl << endl;
cout << "\n\n";
#endif
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void freeConsole()
{
#if defined(BSPF_WINDOWS)
cout << "Press \"Enter\"" << endl << std::flush;
cout << "Press \"Enter\"" << '\n' << std::flush;
FreeConsole();
#endif
}
Expand All @@ -213,7 +213,7 @@ int main(int ac, char* av[])
}
catch(const runtime_error& e)
{
cerr << e.what() << endl;
cerr << e.what() << '\n';
return 0;
}
}
Expand Down
Loading

0 comments on commit 7818787

Please sign in to comment.