activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r908548 - in /activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src: main/decaf/io/ByteArrayInputStream.cpp test/decaf/io/BufferedOutputStreamTest.cpp
Date Wed, 10 Feb 2010 15:46:41 GMT
Author: tabish
Date: Wed Feb 10 15:46:40 2010
New Revision: 908548

URL: http://svn.apache.org/viewvc?rev=908548&view=rev
Log:
Merge in fix from trunk for ByteArrayInputStream performance improvement.

Modified:
    activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp
    activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp?rev=908548&r1=908547&r2=908548&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp
(original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp
Wed Feb 10 15:46:40 2010
@@ -56,8 +56,12 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayInputStream::setByteArray( const unsigned char* buffer,
-                                         std::size_t bufferSize ) {
+void ByteArrayInputStream::setByteArray( const unsigned char* buffer, std::size_t bufferSize
) {
+
+    if( buffer == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Input Buffer cannot be NULL." );
+    }
 
     // We're using the default buffer.
     this->activeBuffer = &this->defaultBuffer;
@@ -67,8 +71,7 @@
     this->defaultBuffer.reserve( bufferSize );
 
     // Copy data to internal buffer.
-    std::back_insert_iterator< std::vector<unsigned char> > iter( this->defaultBuffer
);
-    std::copy( buffer, buffer + bufferSize, iter );
+    this->defaultBuffer.insert( this->defaultBuffer.begin(), buffer, buffer + bufferSize
);
 
     // Start the stream off at the beginning marking begin as the reset point.
     this->markpos = this->activeBuffer->begin();
@@ -76,36 +79,45 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayInputStream::reset() throw ( IOException){
-    if( activeBuffer == NULL ){
-        throw IOException( __FILE__, __LINE__, "Buffer has not been initialized" );
-    }
+void ByteArrayInputStream::reset() throw ( IOException ){
+
+    try{
 
-    // Begin at the Beginning if mark hasn't been called otherwise it
-    // starts at the marked pos.
-    pos = this->markpos;
+        if( activeBuffer == NULL ){
+            throw IOException( __FILE__, __LINE__, "Buffer has not been initialized" );
+        }
+
+        // Begin at the Beginning if mark hasn't been called otherwise it
+        // starts at the marked pos.
+        pos = this->markpos;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 int ByteArrayInputStream::read() throw ( IOException ){
 
-    if( activeBuffer == NULL ){
-        throw IOException(
-            __FILE__, __LINE__,
-            "ByteArrayInputStream::read - Buffer has not been initialized" );
-    }
+    try{
 
-    if( pos == activeBuffer->end() ){
-        return -1;
-    }
+        if( activeBuffer == NULL ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "ByteArrayInputStream::read - Buffer has not been initialized" );
+        }
 
-    return *(pos++);
+        if( pos == activeBuffer->end() ){
+            return -1;
+        }
+
+        return *(pos++);
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int ByteArrayInputStream::read( unsigned char* buffer,
-                                std::size_t offset,
-                                std::size_t bufferSize )
+int ByteArrayInputStream::read( unsigned char* buffer, std::size_t offset, std::size_t bufferSize
)
     throw ( IOException, lang::exceptions::NullPointerException ){
 
     try{
@@ -150,17 +162,22 @@
 std::size_t ByteArrayInputStream::skip( std::size_t num )
     throw ( IOException, lang::exceptions::UnsupportedOperationException ){
 
-    if( activeBuffer == NULL ){
-        throw IOException(
-            __FILE__, __LINE__,
-            "ByteArrayInputStream::skip - Buffer has not been initialized" );
-    }
+    try{
 
-    std::size_t ix = 0;
+        if( activeBuffer == NULL ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "ByteArrayInputStream::skip - Buffer has not been initialized" );
+        }
 
-    // Increment the position until we've skipped the desired number
-    // or we've hit the end of the buffer.
-    for( ; ix < num && pos != activeBuffer->end(); ++ix, ++pos) {}
+        std::size_t ix = 0;
 
-    return ix;
+        // Increment the position until we've skipped the desired number
+        // or we've hit the end of the buffer.
+        for( ; ix < num && pos != activeBuffer->end(); ++ix, ++pos) {}
+
+        return ix;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
 }

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp?rev=908548&r1=908547&r2=908548&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
(original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.1.x/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
Wed Feb 10 15:46:40 2010
@@ -169,8 +169,7 @@
         BufferedOutputStream os( &baos, (std::size_t)512 );
         os.write( (unsigned char*)&testString[0], 0, 500 );
 
-        ByteArrayInputStream bais1( baos.toByteArray(), baos.size() );
-        CPPUNIT_ASSERT_MESSAGE( "Bytes written, not buffered", 0 == bais1.available());
+        CPPUNIT_ASSERT_MESSAGE( "Bytes written, not buffered", NULL == baos.toByteArray()
);
         os.flush();
         ByteArrayInputStream bais2( baos.toByteArray(), baos.size() );
         CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush", 500 == bais2.available()
);
@@ -293,8 +292,7 @@
         ByteArrayOutputStream baos;
         BufferedOutputStream os( &baos );
         os.write('t');
-        ByteArrayInputStream bais1( baos.toByteArray(), baos.size() );
-        CPPUNIT_ASSERT_MESSAGE( "Byte written, not buffered", 0 == bais1.available() );
+        CPPUNIT_ASSERT_MESSAGE( "Byte written, not buffered", NULL == baos.toByteArray()
);
         os.flush();
 
         ByteArrayInputStream bais2( baos.toByteArray(), baos.size() );



Mime
View raw message