From: <man...@us...> - 2013-11-10 00:16:09
|
Revision: 3159 http://sourceforge.net/p/modplug/code/3159 Author: manxorist Date: 2013-11-10 00:15:58 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Do not use std::stringstream for simple string concatenation. Modified Paths: -------------- trunk/OpenMPT/common/version.cpp trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/Moddoc.cpp Modified: trunk/OpenMPT/common/version.cpp =================================================================== --- trunk/OpenMPT/common/version.cpp 2013-11-09 23:33:29 UTC (rev 3158) +++ trunk/OpenMPT/common/version.cpp 2013-11-10 00:15:58 UTC (rev 3159) @@ -10,7 +10,7 @@ #include "stdafx.h" #include "version.h" -#include <sstream> +#include "misc_util.h" #include <cstdlib> @@ -219,21 +219,21 @@ std::string GetRevisionString() { + std::string str; if(GetRevision() == 0) { - return ""; + return str; } - std::ostringstream str; - str << "-r" << GetRevision(); + str = std::string("-r") + Stringify(GetRevision()); if(HasMixedRevisions()) { - str << "!"; + str += "!"; } if(IsDirty()) { - str << "+"; + str += "+"; } - return str.str(); + return str; } std::string GetVersionStringExtended() @@ -263,9 +263,7 @@ { url = url.substr(baseurl.length()); } - std::ostringstream str; - str << url << "@" << GetRevision() << GetStateString(); - return str.str(); + return url + "@" + Stringify(GetRevision()) + GetStateString(); } std::string GetContactString() Modified: trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp 2013-11-09 23:33:29 UTC (rev 3158) +++ trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp 2013-11-10 00:15:58 UTC (rev 3159) @@ -15,7 +15,6 @@ #include "libopenmpt_impl.hpp" #include <limits> -#include <sstream> #include <stdexcept> #include <cmath> @@ -109,25 +108,25 @@ }; // class logfunc_logger static std::string format_exception( const char * const function ) { - std::ostringstream err; + std::string err; try { throw; } catch ( openmpt::exception & e ) { - err - << function << ": " - << "ERROR: " - << e.what(); + err += function; + err += ": "; + err += "ERROR: "; + err += e.what(); } catch ( std::exception & e ) { - err - << function << ": " - << "INTERNAL ERROR: " - << e.what(); + err += function; + err += ": "; + err += "INTERNAL ERROR: "; + err += e.what(); } catch ( ... ) { - err - << function << ": " - << "UNKOWN INTERNAL ERROR"; + err += function; + err += ": "; + err += "UNKOWN INTERNAL ERROR"; } - return err.str(); + return err; } static void report_exception( const char * const function, openmpt_log_func const logfunc = 0, void * const user = 0, openmpt::module_impl * const impl = 0 ) { Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-09 23:33:29 UTC (rev 3158) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-10 00:15:58 UTC (rev 3159) @@ -17,7 +17,6 @@ #include <algorithm> #include <iostream> #include <iterator> -#include <sstream> #include <cmath> #include <cstdlib> @@ -41,19 +40,25 @@ } static std::string get_library_version_string() { - std::ostringstream str; + std::string str; std::uint32_t version = get_library_version(); if ( ( version & 0xffff ) == 0 ) { - str << ((version>>24) & 0xff) << "." << ((version>>16) & 0xff); + str += Stringify((version>>24) & 0xff); + str += "."; + str += Stringify((version>>16) & 0xff); } else { - str << ((version>>24) & 0xff) << "." << ((version>>16) & 0xff) << "." << ((version>>0) & 0xffff); + str += Stringify((version>>24) & 0xff); + str += "."; + str += Stringify((version>>16) & 0xff); + str += "."; + str += Stringify((version>>0) & 0xffff); } if ( MptVersion::IsDirty() ) { - str << ".2-modified"; + str += ".2-modified"; } else if ( MptVersion::HasMixedRevisions() ) { - str << ".1-modified"; + str += ".1-modified"; } - return str.str(); + return str; } static std::string get_core_version_string() { @@ -629,45 +634,47 @@ } else if ( key == std::string("message") ) { std::string retval = m_sndFile->songMessage.GetFormatted( SongMessage::leLF ); if ( retval.empty() ) { - std::ostringstream tmp; + std::string tmp; bool valid = false; for ( INSTRUMENTINDEX i = 1; i <= m_sndFile->GetNumInstruments(); ++i ) { std::string instname = m_sndFile->GetInstrumentName( i ); if ( !instname.empty() ) { valid = true; } - tmp << instname << std::endl; + tmp += instname; + tmp += "\n"; } if ( valid ) { - retval = tmp.str(); + retval = tmp; } } if ( retval.empty() ) { - std::ostringstream tmp; + std::string tmp; bool valid = false; for ( SAMPLEINDEX i = 1; i <= m_sndFile->GetNumSamples(); ++i ) { std::string samplename = m_sndFile->GetSampleName( i ); if ( !samplename.empty() ) { valid = true; } - tmp << samplename << std::endl; + tmp += samplename; + tmp += "\n"; } if ( valid ) { - retval = tmp.str(); + retval = tmp; } } return mod_string_to_utf8( retval ); } else if ( key == std::string("warnings") ) { - std::ostringstream retval; + std::string retval; bool first = true; for ( std::vector<std::string>::const_iterator i = m_loaderMessages.begin(); i != m_loaderMessages.end(); ++i ) { if ( !first ) { - retval << std::endl; + retval += "\n"; first = false; } - retval << *i; + retval += *i; } - return retval.str(); + return retval; } return ""; } Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 23:33:29 UTC (rev 3158) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-10 00:15:58 UTC (rev 3159) @@ -236,12 +236,11 @@ #endif EndWaitCursor(); - std::ostringstream str; - str - << "File: " << lpszPathName << std::endl - << "Last saved with: " << m_SndFile.madeWithTracker << ", you are using OpenMPT " << MptVersion::str << std::endl - << std::endl; - logcapturer.ShowLog(str.str()); + logcapturer.ShowLog(std::string() + + "File: " + lpszPathName + "\n" + + "Last saved with: " + m_SndFile.madeWithTracker + ", you are using OpenMPT " + MptVersion::str + "\n" + + "\n" + ); if ((m_SndFile.m_nType == MOD_TYPE_NONE) || (!m_SndFile.GetNumChannels())) return FALSE; // Midi Import @@ -858,12 +857,13 @@ std::string CModDoc::GetLogString() const //--------------------------------------- { - std::ostringstream ret; + std::string ret; for(std::vector<LogEntry>::const_iterator i=m_Log.begin(); i!=m_Log.end(); ++i) { - ret << (*i).message << "\r\n";//std::endl; + ret += (*i).message; + ret += "\r\n"; } - return ret.str(); + return ret; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |