Commit 4bc01864 authored by Davis King's avatar Davis King

The deserialize() for std::string was written under the assumption that std::string

doesn't store it's data in a contiguous block.  However, that isn't quite the case.
See this discussion:
http://stackoverflow.com/questions/1986966/does-s0-point-to-contiguous-characters-in-a-stdstring

Anyway, I changed deserialize() for std::string to be more efficient and read
directly into the string rather than into a contiguous buffer and then do a copy.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404235
parent 6de8dca1
...@@ -745,27 +745,16 @@ namespace dlib ...@@ -745,27 +745,16 @@ namespace dlib
std::istream& in std::istream& in
) )
{ {
char* buf = 0; unsigned long size;
try try { deserialize(size,in); }
catch (serialization_error& e)
{ throw serialization_error(e.info + "\n while deserializing object of type std::string"); }
item.resize(size);
if (size != 0)
{ {
unsigned long size; in.read(&item[0],size);
try { deserialize(size,in); }
catch (serialization_error& e)
{ throw serialization_error(e.info + "\n while deserializing object of type std::string"); }
buf = new char[size+1];
buf[size] = 0;
in.read(buf,size);
item.assign(buf);
if (!in) throw serialization_error("Error deserializing object of type std::string"); if (!in) throw serialization_error("Error deserializing object of type std::string");
delete [] buf;
}
catch (...)
{
if (buf)
delete [] buf;
item.erase();
throw;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment