activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r551188 - /activemq/activemq-cpp/trunk/src/main/activemq/io/DataInputStream.cpp
Date Wed, 27 Jun 2007 14:57:20 GMT
Author: tabish
Date: Wed Jun 27 07:57:15 2007
New Revision: 551188

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

readString improvements, about twice as fast

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/io/DataInputStream.cpp

Modified: activemq/activemq-cpp/trunk/src/main/activemq/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/io/DataInputStream.cpp?view=diff&rev=551188&r1=551187&r2=551188
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/io/DataInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/io/DataInputStream.cpp Wed Jun 27 07:57:15
2007
@@ -249,22 +249,31 @@
     throw ( io::IOException, io::EOFException ) {
     try {
 
-        std::string retVal;
-        char temp = 0;
+        size_t size = 1024;
+        std::vector<char> buffer;
+        buffer.resize( size );
+        size_t pos = 0;
 
-        while( true ){
-            temp = readChar();
+        while( true ) {
 
-            // if null is found we are done.
-            if( temp == '\0' ){
+            if( inputStream->read( (unsigned char*)( &buffer[pos] ), 1 ) == (size_t)-1
) {
+                throw EOFException(
+                    __FILE__, __LINE__,
+                    "DataInputStream::readString - Reached EOF" );
+            }
+
+            // if null is found we are done
+            if( buffer[pos] == '\0' ){
                 break;
             }
 
-            // Append no matter what
-            retVal += temp;
+            // Resize to hold more if we exceed current size
+            if( ++pos > size ) {
+                buffer.resize( (size *= 2) );
+            }
         }
 
-        return retVal;
+        return &buffer[0];
     }
     AMQ_CATCH_RETHROW( EOFException )
     AMQ_CATCH_RETHROW( IOException )



Mime
View raw message