diff --git a/panda/src/downloader/stringStream.I b/panda/src/downloader/stringStream.I index fe58ee15e5..66481c69ee 100644 --- a/panda/src/downloader/stringStream.I +++ b/panda/src/downloader/stringStream.I @@ -16,7 +16,7 @@ //////////////////////////////////////////////////////////////////// // Function: StringStream::Constructor // Access: Published -// Description: +// Description: //////////////////////////////////////////////////////////////////// INLINE StringStream:: StringStream() : iostream(&_buf) { @@ -80,9 +80,7 @@ INLINE void StringStream:: set_data(const string &data) { _buf.clear(); if (!data.empty()) { - pvector pv; - pv.insert(pv.end(), (const unsigned char *)&data[0], (const unsigned char *)&data[0] + data.size()); - _buf.swap_data(pv); + set_data((const unsigned char *)data.data(), data.size()); } } diff --git a/panda/src/downloader/stringStream.cxx b/panda/src/downloader/stringStream.cxx index bc9f764bf2..a15172ea08 100644 --- a/panda/src/downloader/stringStream.cxx +++ b/panda/src/downloader/stringStream.cxx @@ -13,3 +13,17 @@ //////////////////////////////////////////////////////////////////// #include "stringStream.h" + +//////////////////////////////////////////////////////////////////// +// Function: StringStream::set_data +// Access: Public +// Description: Replaces the contents of the data stream. This +// implicitly reseeks to 0. +//////////////////////////////////////////////////////////////////// +void StringStream:: +set_data(const unsigned char *data, size_t size) { + _buf.clear(); + pvector pv; + pv.insert(pv.end(), data, data + size); + _buf.swap_data(pv); +} diff --git a/panda/src/downloader/stringStream.h b/panda/src/downloader/stringStream.h index fd3f2ad6bc..cc295e5357 100644 --- a/panda/src/downloader/stringStream.h +++ b/panda/src/downloader/stringStream.h @@ -46,6 +46,7 @@ public: #ifndef CPPPARSER INLINE string get_data(); INLINE void set_data(const string &data); + void set_data(const unsigned char *data, size_t size); #endif INLINE void swap_data(pvector &data); @@ -59,4 +60,3 @@ private: #include "stringStream.I" #endif - diff --git a/panda/src/downloader/stringStream_ext.cxx b/panda/src/downloader/stringStream_ext.cxx index 84343420a2..a1c46d6cef 100644 --- a/panda/src/downloader/stringStream_ext.cxx +++ b/panda/src/downloader/stringStream_ext.cxx @@ -71,9 +71,7 @@ set_data(PyObject *data) { "StringStream requires a contiguous buffer"); return; } - pvector pv; - pv.insert(pv.end(), (const unsigned char *)view.buf, (const unsigned char *)view.buf + view.len); - _this->_buf.swap_data(pv); + _this->set_data((const unsigned char *)view.buf, view.len); PyBuffer_Release(&view); return; } @@ -84,9 +82,7 @@ set_data(PyObject *data) { char *buffer; Py_ssize_t length; if (PyString_AsStringAndSize(data, &buffer, &length) != -1) { - pvector pv; - pv.insert(pv.end(), (const unsigned char *)buffer, (const unsigned char *)buffer + length); - _this->_buf.swap_data(pv); + _this->set_data((const unsigned char *)buffer, (size_t)length); } return; }