[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9749: Simplify SimpleBuffer using a
From: |
Bastiaan Jacques |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9749: Simplify SimpleBuffer using a scoped array. |
Date: |
Mon, 15 Sep 2008 16:56:49 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9749
committer: Bastiaan Jacques <address@hidden>
branch nick: trunk
timestamp: Mon 2008-09-15 16:56:49 +0200
message:
Simplify SimpleBuffer using a scoped array.
modified:
libbase/SimpleBuffer.h
------------------------------------------------------------
revno: 9736.2.1
committer: Bastiaan Jacques <address@hidden>
branch nick: simplebuf
timestamp: Mon 2008-09-15 15:55:30 +0200
message:
merge trunk
modified:
libbase/GnashImageJpeg.cpp
libbase/SimpleBuffer.h
libbase/image.cpp
libcore/as_value.cpp
libcore/edit_text_character.cpp
libcore/sprite_instance.cpp
plugin/plugin.cpp
testsuite/actionscript.all/TextField.as
testsuite/libcore.all/AsValueTest.cpp
testsuite/misc-haxe.all/Makefile.am
testsuite/misc-ming.all/Makefile.am
testsuite/misc-ming.all/SharedObjectTest.as
testsuite/misc-ming.all/SharedObjectTest.sol/sol1.sol
testsuite/misc-ming.all/SharedObjectTestRunner.sh
testsuite/swfdec/PASSING
=== modified file 'libbase/SimpleBuffer.h'
--- a/libbase/SimpleBuffer.h 2008-08-04 08:29:21 +0000
+++ b/libbase/SimpleBuffer.h 2008-09-15 13:55:30 +0000
@@ -28,6 +28,8 @@
#include <cassert> // for assert
#include <boost/cstdint.hpp> // for boost::uint8_t
#include <algorithm> // for std::copy
+#include <boost/scoped_array.hpp>
+
namespace gnash {
@@ -51,16 +53,13 @@
///
SimpleBuffer(size_t capacity=0)
:
- _data(0),
_size(0),
_capacity(capacity)
{
- if ( _capacity ) _data = new boost::uint8_t[_capacity];
- }
-
- ~SimpleBuffer()
- {
- delete [] _data;
+ if ( _capacity )
+ {
+ _data.reset(new boost::uint8_t[_capacity]);
+ }
}
/// Copy constructor
@@ -71,14 +70,13 @@
///
SimpleBuffer(const SimpleBuffer& b)
:
- _data(0),
_size(b._size),
_capacity(b._size)
{
if ( _size )
{
- _data = new boost::uint8_t[_size];
- std::copy(b._data, b._data+b._size, _data);
+ _data.reset(new boost::uint8_t[_size]);
+ std::copy(b.data(), b.data()+b.size(), _data.get());
}
}
@@ -106,10 +104,10 @@
size_t capacity() const { return _capacity; }
/// Get a pointer to start of data. May be NULL if size==0.
- boost::uint8_t* data() { return _data; }
+ boost::uint8_t* data() { return _data.get(); }
/// Get a pointer to start of data. May be NULL if size==0.
- const boost::uint8_t* data() const { return _data; }
+ const boost::uint8_t* data() const { return _data.get(); }
/// Resize the buffer
void resize(size_t newSize)
@@ -126,12 +124,14 @@
// TODO: use smalles power of 2 bigger then newCapacity
_capacity = std::max(newCapacity, _capacity*2);
- boost::uint8_t* tmp = _data;
- _data = new boost::uint8_t[_capacity];
- if ( tmp )
+ boost::scoped_array<boost::uint8_t> tmp;
+ tmp.swap(_data);
+
+ _data.reset(new boost::uint8_t[_capacity]);
+
+ if ( tmp.get() )
{
- if ( _size ) std::copy(tmp, tmp+_size, _data);
- delete [] tmp;
+ if ( _size ) std::copy(tmp.get(), tmp.get()+_size,
_data.get());
}
}
@@ -151,7 +151,7 @@
const boost::uint8_t* newData = reinterpret_cast<const
uint8_t*>(inData);
size_t curSize = _size;
resize(curSize+size);
- std::copy(newData, newData+size, _data+curSize);
+ std::copy(newData, newData+size, _data.get()+curSize);
assert(_size == curSize+size);
}
@@ -216,12 +216,10 @@
}
private:
-
- boost::uint8_t* _data;
-
size_t _size;
size_t _capacity;
+ boost::scoped_array<boost::uint8_t> _data;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r9749: Simplify SimpleBuffer using a scoped array.,
Bastiaan Jacques <=