[geos-commits] r3780 - in branches/3.3: . capi

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Mar 5 06:55:16 PST 2013


Author: strk
Date: 2013-03-05 06:55:16 -0800 (Tue, 05 Mar 2013)
New Revision: 3780

Modified:
   branches/3.3/NEWS
   branches/3.3/capi/geos_ts_c.cpp
Log:
Speedup GEOSWKBWriter_read_r (#621)

Patch by Daniel Zeitlin

Modified: branches/3.3/NEWS
===================================================================
--- branches/3.3/NEWS	2013-03-05 14:46:27 UTC (rev 3779)
+++ branches/3.3/NEWS	2013-03-05 14:55:16 UTC (rev 3780)
@@ -6,6 +6,7 @@
     - Fix header guards (#617, #618, #619)
     - WKTWriter::appendCoordinate optimisation
     - Fix centroid computation for collections with empty components (#582)
+    - Speedup GEOSWKBReader_read (#621)
 
 Changes in 3.3.7
 2013-01-22 

Modified: branches/3.3/capi/geos_ts_c.cpp
===================================================================
--- branches/3.3/capi/geos_ts_c.cpp	2013-03-05 14:46:27 UTC (rev 3779)
+++ branches/3.3/capi/geos_ts_c.cpp	2013-03-05 14:55:16 UTC (rev 3780)
@@ -4509,6 +4509,13 @@
     }
 }
 
+struct membuf : public std::streambuf
+{
+  membuf(char* s, std::size_t n)
+  {
+    setg(s, s, s + n);
+  }
+};
 
 Geometry*
 GEOSWKBReader_read_r(GEOSContextHandle_t extHandle, WKBReader *reader, const unsigned char *wkb, size_t size)
@@ -4530,11 +4537,15 @@
 
     try
     {
-        std::string wkbstring(reinterpret_cast<const char*>(wkb), size); // make it binary !
-        std::istringstream is(std::ios_base::binary);
-        is.str(wkbstring);
-        is.seekg(0, std::ios::beg); // rewind reader pointer
-        
+        //std::string wkbstring(reinterpret_cast<const char*>(wkb), size); // make it binary !
+        //std::istringstream is(std::ios_base::binary);
+        //is.str(wkbstring);
+        //is.seekg(0, std::ios::beg); // rewind reader pointer
+
+        // http://stackoverflow.com/questions/2079912/simpler-way-to-create-a-c-memorystream-from-char-size-t-without-copying-t
+        membuf mb((char*)wkb, size);
+        istream is(&mb);
+
         Geometry *g = reader->read(is);
         return g;
     }
@@ -4689,7 +4700,8 @@
     {
         std::ostringstream os(std::ios_base::binary);
         writer->write(*geom, os);
-        std::string wkbstring(os.str());
+
+        const std::string& wkbstring = os.str();
         const std::size_t len = wkbstring.length();
 
         unsigned char *result = NULL;



More information about the geos-commits mailing list