[geos-commits] r3779 - trunk/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue Mar 5 06:46:28 PST 2013
Author: strk
Date: 2013-03-05 06:46:27 -0800 (Tue, 05 Mar 2013)
New Revision: 3779
Modified:
trunk/capi/geos_ts_c.cpp
Log:
Speedup GEOSWKBWriter_read_r (#621)
Patch by Daniel Zeitlin
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2013-03-01 11:58:00 UTC (rev 3778)
+++ trunk/capi/geos_ts_c.cpp 2013-03-05 14:46:27 UTC (rev 3779)
@@ -4556,6 +4556,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)
@@ -4577,11 +4584,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;
}
@@ -4736,7 +4747,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