Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
Maintaining more state to avoid construction/allocation/destruction of 
istringstream.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/209825

Maintaining more state to avoid construction/allocation/destruction of 
istringstream.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/209825
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/api/mem_streambuf.cpp'
--- src/api/mem_streambuf.cpp	2013-12-27 15:11:16 +0000
+++ src/api/mem_streambuf.cpp	2014-03-07 02:12:46 +0000
@@ -17,7 +17,6 @@
 #include "stdafx.h"
 #include <cstring>                      /* for memcpy(3) */
 
-#include <zorba/internal/cxx_util.h>
 #include <zorba/util/mem_streambuf.h>
 
 #include "diagnostics/assert.h"

=== modified file 'src/runtime/csv/csv_impl.cpp'
--- src/runtime/csv/csv_impl.cpp	2014-03-06 19:06:43 +0000
+++ src/runtime/csv/csv_impl.cpp	2014-03-07 02:12:46 +0000
@@ -157,11 +157,10 @@
   return false;
 }
 
-static json::type parse_json( zstring const &s, json::token *ptoken ) {
-  mem_streambuf buf( (char*)s.data(), s.size() );
-  istringstream iss;
-  iss.ios::rdbuf( &buf );
-  json::lexer lex( iss );
+static json::type parse_json( zstring const &s, csv_parse_json_state &state,
+                              json::token *ptoken ) {
+  state.set_data( s.data(), s.size() );
+  json::lexer lex( state.iss_ );
   if ( !lex.next( ptoken, false ) )
     return json::none;
   json::token::type const tt = ptoken->get_type();
@@ -221,9 +220,9 @@
     state->csv_.set_stream( item->getStream() );
   else {
     item->getStringValue2( state->string_ );
-    state->mem_streambuf_.set( state->string_.data(), state->string_.size() );
-    state->iss_.ios::rdbuf( &state->mem_streambuf_ );
-    state->csv_.set_stream( state->iss_ );
+    state->input_buf_.set( state->string_.data(), state->string_.size() );
+    state->input_iss_.ios::rdbuf( &state->input_buf_ );
+    state->csv_.set_stream( state->input_iss_ );
   }
 }
 
@@ -428,7 +427,7 @@
         GENV_ITEMFACTORY->createBoolean( item, false );
       else {
         json::token t;
-        switch ( parse_json( *value, &t ) ) {
+        switch ( parse_json( *value, state->parse_json_state_, &t ) ) {
           case json::boolean:
             GENV_ITEMFACTORY->createBoolean( item, (*value)[0] == 't' );
             break;

=== modified file 'src/runtime/csv/csv_util.h'
--- src/runtime/csv/csv_util.h	2013-08-23 00:43:04 +0000
+++ src/runtime/csv/csv_util.h	2014-03-07 02:12:46 +0000
@@ -17,10 +17,32 @@
 #ifndef ZORBA_CSV_UTIL_H
 #define ZORBA_CSV_UTIL_H
 
+// standard
+#include <sstream>
+
+// Zorba
+#include <zorba/util/mem_streambuf.h>
+
 namespace zorba {
 
 ///////////////////////////////////////////////////////////////////////////////
 
+struct csv_parse_json_state {
+  std::istringstream iss_;
+
+  csv_parse_json_state() {
+    iss_.std::ios::rdbuf( &buf_ );
+  }
+
+  void set_data( char const *s, size_t size ) {
+    buf_.set( const_cast<char*>( s ), size );
+    iss_.seekg( 0 );
+  }
+
+private:
+  mem_streambuf buf_;
+};
+
 namespace missing {
   enum type {
     null,

=== modified file 'src/runtime/csv/pregenerated/csv.h'
--- src/runtime/csv/pregenerated/csv.h	2014-03-06 19:06:43 +0000
+++ src/runtime/csv/pregenerated/csv.h	2014-03-07 02:12:46 +0000
@@ -50,11 +50,12 @@
   bool cast_unquoted_; //
   csv_parser csv_; //
   zstring extra_name_; //
-  std::istringstream iss_; //
+  mem_streambuf input_buf_; //
+  std::istringstream input_iss_; //
   std::vector<store::Item_t> keys_; //
   unsigned line_no_; //
-  mem_streambuf mem_streambuf_; //
   missing::type missing_; //
+  csv_parse_json_state parse_json_state_; //
   bool skip_called_; //
   zstring string_; //
   zstring value_; //

=== modified file 'src/runtime/spec/csv/csv.xml'
--- src/runtime/spec/csv/csv.xml	2014-03-06 19:06:43 +0000
+++ src/runtime/spec/csv/csv.xml	2014-03-07 02:12:46 +0000
@@ -32,11 +32,12 @@
     <zorba:member type="bool" name="cast_unquoted_" defaultValue="true"/>
     <zorba:member type="csv_parser" name="csv_"/>
     <zorba:member type="zstring" name="extra_name_"/>
-    <zorba:member type="std::istringstream" name="iss_"/>
+    <zorba:member type="mem_streambuf" name="input_buf_"/>
+    <zorba:member type="std::istringstream" name="input_iss_"/>
     <zorba:member type="std::vector&lt;store::Item_t&gt;" name="keys_"/>
     <zorba:member type="unsigned" name="line_no_" defaultValue="1"/>
-    <zorba:member type="mem_streambuf" name="mem_streambuf_"/>
     <zorba:member type="missing::type" name="missing_" defaultValue="missing::null"/>
+    <zorba:member type="csv_parse_json_state" name="parse_json_state_"/>
     <zorba:member type="bool" name="skip_called_" defaultValue="false"/>
     <zorba:member type="zstring" name="string_"/>
     <zorba:member type="zstring" name="value_"/>

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to