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 2007/06/10 17:40:28 UTC
svn commit: r545898 -
/activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayInputStream.cpp
Author: tabish
Date: Sun Jun 10 08:40:28 2007
New Revision: 545898
URL: http://svn.apache.org/viewvc?view=rev&rev=545898
Log:
https://issues.apache.org/activemq/browse/AMQCPP-93
Slight tweaks for performance, not much to do since this one is so simple.
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayInputStream.cpp
Modified: activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayInputStream.cpp?view=diff&rev=545898&r1=545897&r2=545898
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/io/ByteArrayInputStream.cpp Sun Jun 10 08:40:28 2007
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "ByteArrayInputStream.h"
#include <algorithm>
@@ -44,10 +44,10 @@
////////////////////////////////////////////////////////////////////////////////
void ByteArrayInputStream::setBuffer( const vector<unsigned char>& buffer ){
-
+
// We're using the default buffer.
activeBuffer = &buffer;
-
+
// Begin at the Beginning.
reset();
}
@@ -57,16 +57,13 @@
std::size_t lbufferSize ){
// We're using the default buffer.
activeBuffer = &defaultBuffer;
-
- // Remove old data
- defaultBuffer.clear();
-
- // Copy data to internal buffer.
- for( std::size_t ix = 0; ix < lbufferSize; ++ix )
- {
- defaultBuffer.push_back(lbuffer[ix]);
- }
-
+
+ // Remove old data
+ defaultBuffer.resize( lbufferSize );
+
+ // Copy to internal buffer
+ std::copy( lbuffer, lbuffer + lbufferSize, &defaultBuffer[0] );
+
// Begin at the Beginning.
reset();
}
@@ -76,7 +73,7 @@
if( activeBuffer == NULL ){
throw IOException( __FILE__, __LINE__, "Buffer has not been initialized" );
}
-
+
// Begin at the Beginning.
pos = activeBuffer->begin();
}
@@ -84,41 +81,41 @@
////////////////////////////////////////////////////////////////////////////////
unsigned char ByteArrayInputStream::read() throw ( IOException ){
if( pos == activeBuffer->end() ){
- throw IOException( __FILE__, __LINE__, "Buffer is empty" );
+ throw IOException( __FILE__, __LINE__, "Buffer is empty" );
}
-
+
return *(pos++);
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t ByteArrayInputStream::read( unsigned char* buffer,
- std::size_t bufferSize )
+std::size_t ByteArrayInputStream::read( unsigned char* buffer,
+ std::size_t bufferSize )
throw ( IOException ){
std::size_t ix = 0;
-
- for( ; ix < bufferSize; ++ix, ++pos)
- {
- if(pos == activeBuffer->end())
- {
- // We don't have enough data to fulfill the request.
- throw IOException( __FILE__, __LINE__, "Reached the end of the buffer" );
- }
-
+
+ if( (std::size_t)distance( pos, activeBuffer->end() ) < bufferSize ) {
+ // We don't have enough data to fulfill the request.
+ throw IOException(
+ __FILE__, __LINE__,
+ "Reached the end of the buffer" );
+ }
+
+ for( ; ix < bufferSize; ++ix, ++pos) {
buffer[ix] = *(pos);
}
-
+
return ix;
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t ByteArrayInputStream::skip( std::size_t num )
+std::size_t ByteArrayInputStream::skip( std::size_t num )
throw ( IOException, exceptions::UnsupportedOperationException ){
-
+
std::size_t ix = 0;
-
+
// 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;
}