activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r552868 - /activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/utils/BooleanStream.cpp
Date Tue, 03 Jul 2007 15:06:33 GMT
Author: tabish
Date: Tue Jul  3 08:06:32 2007
New Revision: 552868

URL: http://svn.apache.org/viewvc?view=rev&rev=552868
Log:
https://issues.apache.org/activemq/browse/AMQCPP-93

Submitting optimized BooleanStream

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/utils/BooleanStream.cpp

Modified: activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/utils/BooleanStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/utils/BooleanStream.cpp?view=diff&rev=552868&r1=552867&r2=552868
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/utils/BooleanStream.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/utils/BooleanStream.cpp
Tue Jul  3 08:06:32 2007
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #include <activemq/connector/openwire/utils/BooleanStream.h>
 
 using namespace std;
@@ -28,7 +28,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 BooleanStream::BooleanStream()
 {
-    this->arrayLimit = 0;    
+    this->arrayLimit = 0;
     this->arrayPos = 0;
     this->bytePos = 0;
 
@@ -63,22 +63,22 @@
 void BooleanStream::writeBoolean( bool value ) throw ( IOException ) {
 
     try{
-        
+
         if( bytePos == 0 ) {
             arrayLimit++;
-            
+
             if( (size_t)arrayLimit >= data.capacity() ) {
                 // re-grow the array if necessary
                 data.resize( data.size() * 2 );
             }
         }
-        
+
         if( value ) {
-            data[arrayPos] |= ( 0x01 << bytePos ); 
+            data[arrayPos] |= ( 0x01 << bytePos );
         }
-        
+
         bytePos++;
-        
+
         // Wrap around when we hit the next byte
         if( bytePos >= 8 ) {
             bytePos=0;
@@ -90,21 +90,21 @@
     AMQ_CATCHALL_THROW( IOException )
 }
 
-///////////////////////////////////////////////////////////////////////////////    
+///////////////////////////////////////////////////////////////////////////////
 void BooleanStream::marshal( DataOutputStream* dataOut ) throw ( IOException ) {
 
     try {
-        
+
         if( arrayLimit < 64 ) {
             dataOut->writeByte( (unsigned char)arrayLimit );
         } else if( arrayLimit < 256 ) { // max value of unsigned char
             dataOut->writeByte( 0xC0 );
-            dataOut->writeByte( (unsigned char)arrayLimit );            
+            dataOut->writeByte( (unsigned char)arrayLimit );
         } else {
             dataOut->writeByte( 0x80 );
-            dataOut->writeShort( arrayLimit );            
+            dataOut->writeShort( arrayLimit );
         }
-        
+
         // Dump the payload
         dataOut->write( &data[0], arrayLimit );
         clear();
@@ -114,53 +114,49 @@
     AMQ_CATCHALL_THROW( IOException )
 }
 
-///////////////////////////////////////////////////////////////////////////////    
+///////////////////////////////////////////////////////////////////////////////
 void BooleanStream::marshal( std::vector< unsigned char >& dataOut ) {
-    
+
     try{
         if( arrayLimit < 64 ) {
             dataOut.push_back( ( unsigned char ) arrayLimit );
         } else if( arrayLimit < 256 ) { // max value of unsigned byte
             dataOut.push_back( ( unsigned char ) 0xC0 );
-            dataOut.push_back( ( unsigned char ) arrayLimit );            
+            dataOut.push_back( ( unsigned char ) arrayLimit );
         } else {
             dataOut.push_back( ( unsigned char ) 0x80 );
             dataOut.push_back( arrayLimit >> 8 );   // High Byte
-            dataOut.push_back( arrayLimit & 0xFF ); // Low Byte 
+            dataOut.push_back( arrayLimit & 0xFF ); // Low Byte
         }
-        
+
         // Insert all data from data into the passed buffer
-        dataOut.insert( dataOut.begin(), &data[0], &data[arrayLimit-1] );
+        std::back_insert_iterator< std::vector<unsigned char> > iter( dataOut
);
+        std::copy( &data[0], &data[arrayLimit-1], iter );
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCH_EXCEPTION_CONVERT( ActiveMQException, IOException )
     AMQ_CATCHALL_THROW( IOException )
 }
 
-///////////////////////////////////////////////////////////////////////////////    
+///////////////////////////////////////////////////////////////////////////////
 void BooleanStream::unmarshal( DataInputStream* dataIn ) throw ( IOException ) {
 
     try{
-            
+
         arrayLimit = (short)( dataIn->readByte() & 0xFF );
-        
+
         if ( arrayLimit == 0xC0 ) {
             arrayLimit = (short)( dataIn->readByte() & 0xFF );
         } else if( arrayLimit == 0x80 ) {
             arrayLimit = dataIn->readShort();
-        } 
-        
-        // Reserve space all at once if needed.
-        if( data.capacity() < (size_t)arrayLimit ) {
-            data.reserve( arrayLimit );
         }
-        
+
         // Make sure we can accomodate all the data.
         data.resize( arrayLimit );
-    
+
         // Make sure we get all the data we are expecting
         dataIn->readFully( &data[0], 0, arrayLimit );
-        
+
         clear();
     }
     AMQ_CATCH_RETHROW( IOException )
@@ -168,13 +164,13 @@
     AMQ_CATCHALL_THROW( IOException )
 }
 
-///////////////////////////////////////////////////////////////////////////////    
+///////////////////////////////////////////////////////////////////////////////
 void BooleanStream::clear() {
     arrayPos = 0;
     bytePos = 0;
 }
 
-///////////////////////////////////////////////////////////////////////////////    
+///////////////////////////////////////////////////////////////////////////////
 int BooleanStream::marshalledSize() {
     if( arrayLimit < 64 ) {
         return 1 + arrayLimit;



Mime
View raw message