Author: tabish
Date: Sun Jun 10 16:23:59 2007
New Revision: 545967
URL: http://svn.apache.org/viewvc?view=rev&rev=545967
Log:
https://issues.apache.org/activemq/browse/AMQCPP-93
Slight tweaks for performance,
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.cpp
activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompFrame.h
activemq/activemq-cpp/trunk/src/main/activemq/io/BlockingByteArrayInputStream.cpp
activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayOutputStream.cpp
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.cpp?view=diff&rev=545967&r1=545966&r2=545967
==============================================================================
---
activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.cpp
(original)
+++
activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.cpp
Sun Jun 10 16:23:59 2007
@@ -50,9 +50,8 @@
try{
clearBody();
- for( size_t i = 0; i < numBytes; ++i ) {
- getContent().push_back( buffer[i] );
- }
+ std::vector<unsigned char>& content = getContent();
+ content.insert( content.end(), buffer, buffer + numBytes );
}
AMQ_CATCH_RETHROW( exceptions::ActiveMQException )
AMQ_CATCHALL_THROW( exceptions::ActiveMQException )
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompFrame.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompFrame.h?view=diff&rev=545967&r1=545966&r2=545967
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompFrame.h
(original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompFrame.h
Sun Jun 10 16:23:59 2007
@@ -123,10 +123,7 @@
body.clear();
// Copy data to internal buffer.
- for( std::size_t ix = 0; ix < numBytes; ++ix )
- {
- body.push_back(bytes[ix]);
- }
+ body.insert( body.end(), bytes, bytes + numBytes );
}
private:
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/io/BlockingByteArrayInputStream.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/io/BlockingByteArrayInputStream.cpp?view=diff&rev=545967&r1=545966&r2=545967
==============================================================================
---
activemq/activemq-cpp/trunk/src/main/activemq/io/BlockingByteArrayInputStream.cpp
(original)
+++
activemq/activemq-cpp/trunk/src/main/activemq/io/BlockingByteArrayInputStream.cpp
Sun Jun 10 16:23:59 2007
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "BlockingByteArrayInputStream.h"
#include <algorithm>
@@ -30,10 +30,10 @@
}
////////////////////////////////////////////////////////////////////////////////
-BlockingByteArrayInputStream::BlockingByteArrayInputStream(
+BlockingByteArrayInputStream::BlockingByteArrayInputStream(
const unsigned char* buffer,
std::size_t bufferSize ){
-
+
closing = false;
setByteArray( buffer, bufferSize );
}
@@ -46,19 +46,16 @@
void BlockingByteArrayInputStream::setByteArray( const unsigned char* lbuffer,
std::size_t lbufferSize ){
synchronized( this ){
-
- // Remove old data
+
+ // Remove old data
this->buffer.clear();
-
+
// Copy data to internal buffer.
- for( std::size_t ix = 0; ix < lbufferSize; ++ix )
- {
- this->buffer.push_back(lbuffer[ix]);
- }
-
+ this->buffer.insert( this->buffer.end(), lbuffer, lbuffer +
lbufferSize );
+
// Begin at the Beginning.
pos = this->buffer.begin();
-
+
// Notify any listening threds that there is now data available.
notifyAll();
}
@@ -66,15 +63,15 @@
////////////////////////////////////////////////////////////////////////////////
void BlockingByteArrayInputStream::close() throw (cms::CMSException){
-
+
synchronized( this ){
-
+
// Indicate that we're shutting down.
closing = true;
-
+
// Clear out the buffer.
buffer.clear();
-
+
// Notify that this stream is shutting down.
notifyAll();
}
@@ -82,69 +79,69 @@
////////////////////////////////////////////////////////////////////////////////
unsigned char BlockingByteArrayInputStream::read() throw ( IOException ){
-
+
synchronized( this ){
-
+
while( !closing ){
-
- if( pos != buffer.end() ){
+
+ if( pos != buffer.end() ){
return *(pos++);
}
-
+
// Wait for more data
wait();
}
-
+
throw IOException( __FILE__, __LINE__, "close occurred during read" );
}
-
+
return 0;
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t BlockingByteArrayInputStream::read( unsigned char* buffer,
- std::size_t bufferSize )
+std::size_t BlockingByteArrayInputStream::read( unsigned char* buffer,
+ std::size_t bufferSize )
throw ( IOException ){
synchronized( this ){
-
+
std::size_t ix = 0;
-
+
for( ; ix < bufferSize && !closing; ++ix, ++pos)
{
if(pos == this->buffer.end())
- {
+ {
// Wait for more data to come in.
wait();
}
-
+
if( !closing ){
buffer[ix] = *(pos);
}
}
-
+
if( closing ){
throw IOException( __FILE__, __LINE__, "close occurred during
read" );
}
-
+
return ix;
}
-
+
return 0;
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t BlockingByteArrayInputStream::skip( std::size_t num )
+std::size_t BlockingByteArrayInputStream::skip( std::size_t num )
throw ( io::IOException, exceptions::UnsupportedOperationException ){
-
+
std::size_t ix = 0;
-
+
synchronized( this ){
-
+
// Increment the pos until we'v skipped the desired num
// or we've hit the end of the buffer.
- for( ; ix < num && !closing && pos != buffer.end(); ++ix, ++pos) {}
+ for( ; ix < num && !closing && pos != buffer.end(); ++ix, ++pos) {}
}
-
+
return ix;
}
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayOutputStream.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayOutputStream.cpp?view=diff&rev=545967&r1=545966&r2=545967
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayOutputStream.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayOutputStream.cpp
Sun Jun 10 16:23:59 2007
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "ByteArrayOutputStream.h"
#include <algorithm>
@@ -47,21 +47,17 @@
}
////////////////////////////////////////////////////////////////////////////////
-void ByteArrayOutputStream::write( unsigned char c )
+void ByteArrayOutputStream::write( unsigned char c )
throw ( IOException )
{
- activeBuffer->push_back( c );
+ activeBuffer->push_back( c );
}
-////////////////////////////////////////////////////////////////////////////////
-void ByteArrayOutputStream::write( const unsigned char* buffer,
- std::size_t len )
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::write( const unsigned char* buffer,
+ std::size_t len )
throw ( IOException )
-{
- // Iterate until all the data is written.
- for( std::size_t ix = 0; ix < len; ++ix)
- {
- activeBuffer->push_back( buffer[ix] );
- }
+{
+ activeBuffer->insert( activeBuffer->end(), buffer, buffer + len );
}