Fixes local copy optimization

The previous optimization #32 has problem that restoration requires
assignment operator.
Change the backup/restore process using a template wrapper class to
select code path.
This commit is contained in:
Milo Yip
2014-07-02 23:49:47 +08:00
parent 5852c42bb9
commit 9aec8d6ad4
3 changed files with 92 additions and 63 deletions

View File

@@ -623,8 +623,9 @@ public:
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
private:
// Not support copy constructor.
// Prohibit copy constructor & assignment operator.
CustomStringStream(const CustomStringStream&);
CustomStringStream& operator=(const CustomStringStream&);
const Ch* src_; //!< Current read position.
const Ch* head_; //!< Original head of the string.
@@ -637,7 +638,7 @@ namespace rapidjson {
template <typename Encoding>
struct StreamTraits<CustomStringStream<Encoding> > {
typedef CustomStringStream<Encoding> StreamCopyType;
enum { copyOptimization = 1 };
};
} // namespace rapdijson