commit 444cec07
No longer construct a stingstream everytime it is needed but resuses where possible
git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@147 9d7177f8-192b-0410-8f35-a16a89829b06
Changed files
| M | source/code/BlockGame.cpp before |
| M | source/code/common.cc before |
| M | source/code/main.cpp before |
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp
index 279b231..aac7667 100644
--- a/source/code/BlockGame.cpp
+++ b/source/code/BlockGame.cpp
@@ -26,6 +26,8 @@ http://blockattack.sf.net
#include<boost/lexical_cast.hpp>
+static stringstream ss; //Used for internal formatting
+
////////////////////////////////////////////////////////////////////////////////
//The BloackGame class represents a board, score, time etc. for a single player/
////////////////////////////////////////////////////////////////////////////////
@@ -2252,7 +2254,9 @@ void BlockGame::ActionPerformed(int action, string param)
void BlockGame::PerformAction(int tick, int action, string param)
{
- stringstream ss(param);
+ ss.str(std::string());
+ ss.clear();
+ ss << param;
int p1,p2;
Uint32 p3;
switch(action)
diff --git a/source/code/common.cc b/source/code/common.cc
index ee4aeb0..7b4f5fe 100644
--- a/source/code/common.cc
+++ b/source/code/common.cc
@@ -24,17 +24,21 @@ http://blockattack.sf.net
#include "common.h"
#include <sstream>
+static stringstream converter;
+
//Function to convert numbers to string
string itoa(int num)
{
- stringstream converter;
+ converter.str(std::string());
+ converter.clear();
converter << num;
return converter.str();
}
string double2str(double num)
{
- stringstream converter;
+ converter.str(std::string());
+ converter.clear();
converter << num;
return converter.str();
}
@@ -48,7 +52,8 @@ double str2double(string str2parse)
{
try
{
- stringstream converter(str2parse);
+ converter.clear();
+ converter.str(str2parse);
double val = 0.0;
converter >> val;
return val;
@@ -68,7 +73,8 @@ int str2int(string str2parse)
{
try
{
- stringstream converter(str2parse);
+ converter.clear();
+ converter.str(str2parse);
int val = 0;
converter >> val;
return val;
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 976baf2..61b5132 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -805,10 +805,14 @@ void UnloadImages()
return converter.str();
}*/
+
+static stringstream converter;
+
//Function to convert numbers to string (2 diget)
static string itoa2(int num)
{
- stringstream converter;
+ converter.str(std::string());
+ converter.clear();
if(num<10)
converter << "0";
converter << num;