From: <man...@us...> - 2014-03-23 14:46:47
|
Revision: 3937 http://sourceforge.net/p/modplug/code/3937 Author: manxorist Date: 2014-03-23 14:46:39 +0000 (Sun, 23 Mar 2014) Log Message: ----------- [Ref] serialization_utils: Avoid dragging in the whole iostream library in the header. Use a std::string instead of a std::ostringstream to cache the map data when writing. Modified Paths: -------------- trunk/OpenMPT/common/serialization_utils.cpp trunk/OpenMPT/common/serialization_utils.h trunk/OpenMPT/soundlib/Sndfile.cpp Modified: trunk/OpenMPT/common/serialization_utils.cpp =================================================================== --- trunk/OpenMPT/common/serialization_utils.cpp 2014-03-22 19:54:16 UTC (rev 3936) +++ trunk/OpenMPT/common/serialization_utils.cpp 2014-03-23 14:46:39 UTC (rev 3937) @@ -12,7 +12,10 @@ #include "serialization_utils.h" +#include <istream> #include <iterator> // for back_inserter +#include <ostream> +#include <sstream> #include "misc_util.h" @@ -365,24 +368,29 @@ rposDataStart, nDatasize); + std::ostringstream mapStream; + if(m_nIdbytes > 0) { if (m_nIdbytes != IdSizeVariable && nIdSize != m_nIdbytes) { AddWriteNote(SNW_CHANGING_IDSIZE_WITH_FIXED_IDSIZESETTING); return; } if (m_nIdbytes == IdSizeVariable) //Variablesize ID? - WriteAdaptive12(m_MapStream, static_cast<uint16>(nIdSize)); + WriteAdaptive12(mapStream, static_cast<uint16>(nIdSize)); if(nIdSize > 0) - m_MapStream.write(pId, nIdSize); + mapStream.write(pId, nIdSize); } if (GetFlag(RwfWMapStartPosEntry)) //Startpos - WriteAdaptive1248(m_MapStream, rposDataStart); + WriteAdaptive1248(mapStream, rposDataStart); if (GetFlag(RwfWMapSizeEntry)) //Entrysize - WriteAdaptive1248(m_MapStream, nDatasize); + WriteAdaptive1248(mapStream, nDatasize); if (GetFlag(RwfWMapDescEntry)) //Entry descriptions - WriteAdaptive12String(m_MapStream, std::string(pszDesc)); + WriteAdaptive12String(mapStream, std::string(pszDesc)); + + m_MapStreamString.append(mapStream.str()); + } @@ -827,7 +835,6 @@ { std::ostream& oStrm = *m_pOstrm; const Postype posDataEnd = oStrm.tellp(); - std::string mapStreamStr = m_MapStream.str(); Postype posMapStart = oStrm.tellp(); @@ -836,7 +843,7 @@ if (GetFlag(RwfRwHasMap)) //Write map { - oStrm.write(mapStreamStr.c_str(), mapStreamStr.length()); + oStrm.write(m_MapStreamString.c_str(), m_MapStreamString.length()); } const Postype posMapEnd = oStrm.tellp(); Modified: trunk/OpenMPT/common/serialization_utils.h =================================================================== --- trunk/OpenMPT/common/serialization_utils.h 2014-03-22 19:54:16 UTC (rev 3936) +++ trunk/OpenMPT/common/serialization_utils.h 2014-03-23 14:46:39 UTC (rev 3937) @@ -12,11 +12,9 @@ #include <algorithm> #include <bitset> -#include <istream> +#include <iosfwd> #include <limits> -#include <sstream> #include <string> -#include <ostream> #include <vector> #ifdef HAS_TYPE_TRAITS @@ -474,7 +472,7 @@ Postype m_posEntrycount; // Write: Pos of entrycount field. Postype m_posMapPosField; // Write: Pos of map position field. - std::ostringstream m_MapStream; // Write: Map stream. + std::string m_MapStreamString; // Write: Map stream string. }; Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2014-03-22 19:54:16 UTC (rev 3936) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2014-03-23 14:46:39 UTC (rev 3937) @@ -23,7 +23,7 @@ #include "tuningcollection.h" #include "../common/StringFixer.h" #include "FileReader.h" -#include <iostream> +#include <sstream> #include <time.h> #ifndef NO_ARCHIVE_SUPPORT This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |