git repos / blockattack-game

commit 444cec07

sago007 · 2012-05-05 16:42
444cec0742a60eef8b4d24ebeca19fe311a4f0c5 patch · browse files
parent 79d3c1d3221aabedd7fe08359243d8c9447c2623

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;