https://issues.apache.org/jira/browse/AMQCPP-548
diff --git a/activemq-cpp/src/main/decaf/lang/Integer.cpp b/activemq-cpp/src/main/decaf/lang/Integer.cpp
index 04d011d..68ce6a5 100644
--- a/activemq-cpp/src/main/decaf/lang/Integer.cpp
+++ b/activemq-cpp/src/main/decaf/lang/Integer.cpp
@@ -22,6 +22,7 @@
#include <decaf/lang/Integer.h>
#include <decaf/lang/Character.h>
#include <sstream>
+#include <vector>
using namespace decaf;
using namespace decaf::lang;
@@ -142,7 +143,7 @@
// Save length and allocate a new buffer for the string, add one
// more for the null character.
int length = count;
- char* buffer = new char[length + 1];
+ std::vector<char> buffer(length);
do {
int ch = 0 - (j % radix);
@@ -158,12 +159,7 @@
buffer[0] = '-';
}
- // Ensure there's a null
- buffer[length] = 0;
- std::string result(&buffer[0]);
- delete[] buffer;
-
- return result;
+ return std::string(&buffer[0], length);
}
////////////////////////////////////////////////////////////////////////////////
@@ -183,19 +179,14 @@
// Save length and allocate a new buffer for the string, add one
// more for the null character.
int length = count;
- char* buffer = new char[length + 1];
+ std::vector<char> buffer(length);
do {
buffer[--count] = (char) ((value & 1) + '0');
value >>= 1;
} while (count > 0);
- // Ensure there's a null
- buffer[length] = 0;
- std::string result(&buffer[0]);
- delete[] buffer;
-
- return result;
+ return std::string(&buffer[0], length);
}
////////////////////////////////////////////////////////////////////////////////
@@ -215,19 +206,14 @@
// Save length and allocate a new buffer for the string, add one
// more for the null character.
int length = count;
- char* buffer = new char[length + 1];
+ std::vector<char> buffer(length);
do {
buffer[--count] = (char) ((uvalue & 7) + '0');
uvalue >>= 3;
} while (count > 0);
- // Ensure there's a null
- buffer[length] = 0;
- std::string result(&buffer[0]);
- delete[] buffer;
-
- return result;
+ return std::string(&buffer[0], length);
}
////////////////////////////////////////////////////////////////////////////////
@@ -247,7 +233,7 @@
// Save length and allocate a new buffer for the string, add one
// more for the null character.
int length = count;
- char* buffer = new char[length + 1];
+ std::vector<char> buffer(length);
do {
int t = value & 15;
@@ -260,12 +246,7 @@
value >>= 4;
} while (count > 0);
- // Ensure there's a null
- buffer[length] = 0;
- std::string result(&buffer[0]);
- delete[] buffer;
-
- return result;
+ return std::string(&buffer[0], length);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp b/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
index 284cae7..3d74383 100644
--- a/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
+++ b/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
@@ -45,12 +45,18 @@
public:
MutexProperties() : monitor(NULL), name() {
- this->name = DEFAULT_NAME_PREFIX + Integer::toString( ++id );
+ std::string idStr = Integer::toString(++id);
+ this->name.reserve(DEFAULT_NAME_PREFIX.length() + idStr.length());
+ this->name.append(DEFAULT_NAME_PREFIX);
+ this->name.append(idStr);
}
MutexProperties(const std::string& name) : monitor(NULL), name(name) {
if (this->name.empty()) {
- this->name = DEFAULT_NAME_PREFIX + Integer::toString(++id);
+ std::string idStr = Integer::toString(++id);
+ this->name.reserve(DEFAULT_NAME_PREFIX.length() + idStr.length());
+ this->name.append(DEFAULT_NAME_PREFIX);
+ this->name.append(idStr);
}
}