diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2020-03-22 13:54:31 (GMT) |
---|---|---|
committer | Alex Turbov <i.zaufi@gmail.com> | 2020-03-26 03:36:57 (GMT) |
commit | 3fdd8db3aaf4c804dd24a59913650ad024c8343e (patch) | |
tree | 1b2b9ef7f9b724b802b4cecdc2554f5abaf41a43 /Source/cmCacheManager.cxx | |
parent | ea54f8d44199502d6d02369ea0a2de4e9ef8c1ca (diff) | |
download | CMake-3fdd8db3aaf4c804dd24a59913650ad024c8343e.zip CMake-3fdd8db3aaf4c804dd24a59913650ad024c8343e.tar.gz CMake-3fdd8db3aaf4c804dd24a59913650ad024c8343e.tar.bz2 |
Refactor: Avoid `std::endl` where it's not necessary (part 1)
The `std::endl` manupulator, except inserting `\n` character, also
performs `os.flush()`, which may leads to undesired effects (like
disk I/O in the middle of forming data strings). For the
`std::stringstream` it also has no meaning.
Diffstat (limited to 'Source/cmCacheManager.cxx')
-rw-r--r-- | Source/cmCacheManager.cxx | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index 8789f6e..cfa8dc7 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -77,7 +77,7 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal, } while (realbuffer[0] == '/' && realbuffer[1] == '/') { if ((realbuffer[2] == '\\') && (realbuffer[3] == 'n')) { - helpString += "\n"; + helpString += '\n'; helpString += &realbuffer[4]; } else { helpString += &realbuffer[2]; @@ -117,8 +117,8 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal, } } else { std::ostringstream error; - error << "Parse error in cache file " << cacheFile; - error << " on line " << lineno << ". Offending entry: " << realbuffer; + error << "Parse error in cache file " << cacheFile << " on line " + << lineno << ". Offending entry: " << realbuffer; cmSystemTools::Error(error.str()); } } @@ -217,7 +217,7 @@ void cmCacheManager::WritePropertyEntries(std::ostream& os, CacheIterator i, cmCacheManager::OutputKey(os, key); os << ":INTERNAL="; cmCacheManager::OutputValue(os, *value); - os << "\n"; + os << '\n'; cmCacheManager::OutputNewlineTruncationWarning(os, key, *value, messenger); } @@ -268,31 +268,29 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger) /* clang-format off */ fout << "# This is the CMakeCache file.\n" - << "# For build in directory: " << currentcwd << "\n" - << "# It was generated by CMake: " - << cmSystemTools::GetCMakeCommand() << std::endl; + "# For build in directory: " << currentcwd << "\n" + "# It was generated by CMake: " + << cmSystemTools::GetCMakeCommand() + << "\n" + "# You can edit this file to change values found and used by cmake." + "\n" + "# If you do not want to change any of the values, simply exit the " + "editor.\n" + "# If you do want to change a value, simply edit, save, and exit " + "the editor.\n" + "# The syntax for the file is as follows:\n" + "# KEY:TYPE=VALUE\n" + "# KEY is the name of a variable in the cache.\n" + "# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!." + "\n" + "# VALUE is the current value for the KEY.\n" + "\n" + "########################\n" + "# EXTERNAL cache entries\n" + "########################\n" + "\n"; /* clang-format on */ - /* clang-format off */ - fout << "# You can edit this file to change values found and used by cmake." - << std::endl - << "# If you do not want to change any of the values, simply exit the " - "editor." << std::endl - << "# If you do want to change a value, simply edit, save, and exit " - "the editor." << std::endl - << "# The syntax for the file is as follows:\n" - << "# KEY:TYPE=VALUE\n" - << "# KEY is the name of a variable in the cache.\n" - << "# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT " - "TYPE!." << std::endl - << "# VALUE is the current value for the KEY.\n\n"; - /* clang-format on */ - - fout << "########################\n"; - fout << "# EXTERNAL cache entries\n"; - fout << "########################\n"; - fout << "\n"; - for (auto const& i : this->Cache) { CacheEntry const& ce = i.second; cmStateEnums::CacheEntryType t = ce.Type; @@ -309,20 +307,20 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger) cmCacheManager::OutputHelpString(fout, "Missing description"); } cmCacheManager::OutputKey(fout, i.first); - fout << ":" << cmState::CacheEntryTypeToString(t) << "="; + fout << ':' << cmState::CacheEntryTypeToString(t) << '='; cmCacheManager::OutputValue(fout, ce.Value); - fout << "\n"; + fout << '\n'; cmCacheManager::OutputNewlineTruncationWarning(fout, i.first, ce.Value, messenger); - fout << "\n"; + fout << '\n'; } } - fout << "\n"; - fout << "########################\n"; - fout << "# INTERNAL cache entries\n"; - fout << "########################\n"; - fout << "\n"; + fout << "\n" + "########################\n" + "# INTERNAL cache entries\n" + "########################\n" + "\n"; for (cmCacheManager::CacheIterator i = this->NewIterator(); !i.IsAtEnd(); i.Next()) { @@ -338,14 +336,14 @@ bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger) cmCacheManager::OutputHelpString(fout, *help); } cmCacheManager::OutputKey(fout, i.GetName()); - fout << ":" << cmState::CacheEntryTypeToString(t) << "="; + fout << ':' << cmState::CacheEntryTypeToString(t) << '='; cmCacheManager::OutputValue(fout, i.GetValue()); - fout << "\n"; + fout << '\n'; cmCacheManager::OutputNewlineTruncationWarning(fout, i.GetName(), i.GetValue(), messenger); } } - fout << "\n"; + fout << '\n'; fout.Close(); std::string checkCacheFile = cmStrCat(path, "/CMakeFiles"); cmSystemTools::MakeDirectory(checkCacheFile); @@ -428,7 +426,7 @@ void cmCacheManager::OutputHelpString(std::ostream& fout, fout << "\\n"; } oneLine = helpString.substr(pos, i - pos); - fout << oneLine << "\n"; + fout << oneLine << '\n'; pos = i; } } @@ -450,7 +448,7 @@ void cmCacheManager::OutputWarningComment(std::ostream& fout, fout << "\\n"; } oneLine = message.substr(pos, i - pos); - fout << oneLine << "\n"; + fout << oneLine << '\n'; pos = i; } } @@ -517,17 +515,17 @@ cmProp cmCacheManager::GetInitializedCacheValue(const std::string& key) const void cmCacheManager::PrintCache(std::ostream& out) const { - out << "=================================================" << std::endl; - out << "CMakeCache Contents:" << std::endl; + out << "=================================================\n" + "CMakeCache Contents:\n"; for (auto const& i : this->Cache) { if (i.second.Type != cmStateEnums::INTERNAL) { - out << i.first << " = " << i.second.Value << std::endl; + out << i.first << " = " << i.second.Value << '\n'; } } - out << "\n\n"; - out << "To change values in the CMakeCache, " << std::endl - << "edit CMakeCache.txt in your output directory.\n"; - out << "=================================================" << std::endl; + out << "\n\n" + "To change values in the CMakeCache, \n" + "edit CMakeCache.txt in your output directory.\n" + "=================================================\n"; } void cmCacheManager::AddCacheEntry(const std::string& key, const char* value, |