summaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/tree/buffer.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-01-08 17:01:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-01-08 17:01:08 +0200
commite6d52ecfa2379b1f7f3007e65ded5e4076abc5e9 (patch)
tree70258beb5308c1ec041daea08d41aa745741a0c6 /libxsd/xsd/cxx/tree/buffer.txx
parent3f8c237b1abe02df8147170f2fc037edc3f384db (diff)
Add support in buffer class for reusing existing buffer without freeing it
Diffstat (limited to 'libxsd/xsd/cxx/tree/buffer.txx')
-rw-r--r--libxsd/xsd/cxx/tree/buffer.txx24
1 files changed, 9 insertions, 15 deletions
diff --git a/libxsd/xsd/cxx/tree/buffer.txx b/libxsd/xsd/cxx/tree/buffer.txx
index ab11f40..f88f140 100644
--- a/libxsd/xsd/cxx/tree/buffer.txx
+++ b/libxsd/xsd/cxx/tree/buffer.txx
@@ -60,20 +60,10 @@ namespace xsd
if (size > capacity)
throw bounds<C> ();
- if (own)
- {
- data_ = reinterpret_cast<char*> (data);
- size_ = size;
- capacity_ = capacity;
- }
- else
- {
- this->capacity (capacity);
- size_ = size;
-
- if (size_)
- std::memcpy (data_, data, size_);
- }
+ data_ = reinterpret_cast<char*> (data);
+ size_ = size;
+ capacity_ = capacity;
+ free_ = own;
}
template <typename C>
@@ -111,14 +101,17 @@ namespace xsd
char* tmp_data (data_);
size_t tmp_size (size_);
size_t tmp_capacity (capacity_);
+ bool tmp_free (free_);
data_ = other.data_;
size_ = other.size_;
capacity_ = other.capacity_;
+ free_ = other.free_;
other.data_ = tmp_data;
other.size_ = tmp_size;
other.capacity_ = tmp_capacity;
+ other.free_ = tmp_free;
}
template <typename C>
@@ -139,11 +132,12 @@ namespace xsd
if (copy && size_ > 0)
std::memcpy (data, data_, size_);
- if (data_)
+ if (free_ && data_)
operator delete (data_);
data_ = data;
capacity_ = capacity;
+ free_ = true;
return true;
}