You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2014/08/05 22:21:06 UTC
[2/2] git commit: https://issues.apache.org/jira/browse/AMQCPP-548
https://issues.apache.org/jira/browse/AMQCPP-548
Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/9c270613
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/9c270613
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/9c270613
Branch: refs/heads/trunk
Commit: 9c2706139fbff7c3e73160cf90fb85b51481a28c
Parents: 2e9e0c6
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue Aug 5 16:20:56 2014 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue Aug 5 16:20:56 2014 -0400
----------------------------------------------------------------------
activemq-cpp/src/main/decaf/lang/Integer.cpp | 37 +++++---------------
.../src/main/decaf/util/concurrent/Mutex.cpp | 10 ++++--
2 files changed, 17 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/9c270613/activemq-cpp/src/main/decaf/lang/Integer.cpp
----------------------------------------------------------------------
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 @@ std::string Integer::toString(int value, int radix) {
// 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 @@ std::string Integer::toString(int value, int radix) {
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 @@ std::string Integer::toBinaryString(int value) {
// 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 @@ std::string Integer::toOctalString(int value) {
// 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 @@ std::string Integer::toHexString(int value) {
// 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 @@ std::string Integer::toHexString(int value) {
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);
}
////////////////////////////////////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/9c270613/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
----------------------------------------------------------------------
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 @@ namespace concurrent {
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);
}
}