Ver código fonte

Remove deprecated usage of sprintf

Ivan Savenko 2 anos atrás
pai
commit
94597e7af6
2 arquivos alterados com 7 adições e 8 exclusões
  1. 2 5
      lib/HeroBonus.cpp
  2. 5 3
      lib/int3.h

+ 2 - 5
lib/HeroBonus.cpp

@@ -663,9 +663,7 @@ int IBonusBearer::valOfBonuses(Bonus::BonusType type, const CSelector &selector)
 int IBonusBearer::valOfBonuses(Bonus::BonusType type, int subtype) const
 {
 	//This part is performance-critical
-
-	char cachingStr[20] = {};
-	std::sprintf(cachingStr, "type_%ds_%d", (int)type, subtype);
+	std::string cachingStr = "type_" + std::to_string(int(type)) + "_" + std::to_string(subtype);
 
 	CSelector s = Selector::type()(type);
 	if(subtype != -1)
@@ -694,8 +692,7 @@ bool IBonusBearer::hasBonus(const CSelector &selector, const CSelector &limit, c
 bool IBonusBearer::hasBonusOfType(Bonus::BonusType type, int subtype) const
 {
 	//This part is performance-ciritcal
-	char cachingStr[20] = {};
-	std::sprintf(cachingStr, "type_%ds_%d", (int)type, subtype);
+	std::string cachingStr = "type_" + std::to_string(int(type)) + "_" + std::to_string(subtype);
 
 	CSelector s = Selector::type()(type);
 	if(subtype != -1)

+ 5 - 3
lib/int3.h

@@ -161,10 +161,12 @@ public:
 	std::string toString() const
 	{
 		//Performance is important here
-		char str[16] = {};
-		std::sprintf(str, "(%d %d %d)", x, y, z);
+		std::string result = "{" +
+				std::to_string(x) + " " +
+				std::to_string(y) + " " +
+				std::to_string(z) + "}";
 
-		return std::string(str);
+		return result;
 	}
 
 	bool valid() const //Should be named "isValid"?