- IFC: use boost::make_shared to cut the number of allocations by 50%.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1022 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/1/head
parent
326b11b72f
commit
b9f14beb76
|
@ -124,7 +124,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <boost/scoped_array.hpp>
|
#include <boost/scoped_array.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/shared_array.hpp>
|
#include <boost/shared_array.hpp>
|
||||||
//#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
|
|
|
@ -210,7 +210,7 @@ namespace STEP {
|
||||||
*
|
*
|
||||||
* @throw SyntaxError
|
* @throw SyntaxError
|
||||||
*/
|
*/
|
||||||
static const DataType* Parse(const char*& inout,
|
static boost::shared_ptr<const EXPRESS::DataType> Parse(const char*& inout,
|
||||||
uint64_t line = SyntaxError::LINE_NOT_SPECIFIED,
|
uint64_t line = SyntaxError::LINE_NOT_SPECIFIED,
|
||||||
const EXPRESS::ConversionSchema* schema = NULL);
|
const EXPRESS::ConversionSchema* schema = NULL);
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ namespace STEP {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** @see DaraType::Parse */
|
/** @see DaraType::Parse */
|
||||||
static const LIST* Parse(const char*& inout,
|
static boost::shared_ptr<const EXPRESS::LIST> Parse(const char*& inout,
|
||||||
uint64_t line = SyntaxError::LINE_NOT_SPECIFIED,
|
uint64_t line = SyntaxError::LINE_NOT_SPECIFIED,
|
||||||
const EXPRESS::ConversionSchema* schema = NULL);
|
const EXPRESS::ConversionSchema* schema = NULL);
|
||||||
|
|
||||||
|
@ -654,11 +654,8 @@ namespace STEP {
|
||||||
mutable uint64_t id;
|
mutable uint64_t id;
|
||||||
const char* const type;
|
const char* const type;
|
||||||
DB& db;
|
DB& db;
|
||||||
|
|
||||||
union {
|
mutable const char* args;
|
||||||
mutable const EXPRESS::LIST* conv_args;
|
|
||||||
mutable const char* args;
|
|
||||||
};
|
|
||||||
mutable Object* obj;
|
mutable Object* obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ STEP::DB* STEP::ReadFileHeader(boost::shared_ptr<IOStream> stream)
|
||||||
if (s.substr(0,11) == "FILE_SCHEMA") {
|
if (s.substr(0,11) == "FILE_SCHEMA") {
|
||||||
const char* sz = s.c_str()+11;
|
const char* sz = s.c_str()+11;
|
||||||
SkipSpaces(sz,&sz);
|
SkipSpaces(sz,&sz);
|
||||||
std::auto_ptr< const EXPRESS::DataType > schema = std::auto_ptr< const EXPRESS::DataType >( EXPRESS::DataType::Parse(sz) );
|
boost::shared_ptr< const EXPRESS::DataType > schema = EXPRESS::DataType::Parse(sz);
|
||||||
|
|
||||||
// the file schema should be a regular list entity, although it usually contains exactly one entry
|
// the file schema should be a regular list entity, although it usually contains exactly one entry
|
||||||
// since the list itself is contained in a regular parameter list, we actually have
|
// since the list itself is contained in a regular parameter list, we actually have
|
||||||
|
@ -253,7 +253,7 @@ void STEP::ReadFile(DB& db,const EXPRESS::ConversionSchema& scheme,
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
const EXPRESS::DataType* EXPRESS::DataType::Parse(const char*& inout,uint64_t line, const EXPRESS::ConversionSchema* schema /*= NULL*/)
|
boost::shared_ptr<const EXPRESS::DataType> EXPRESS::DataType::Parse(const char*& inout,uint64_t line, const EXPRESS::ConversionSchema* schema /*= NULL*/)
|
||||||
{
|
{
|
||||||
const char* cur = inout;
|
const char* cur = inout;
|
||||||
SkipSpaces(&cur);
|
SkipSpaces(&cur);
|
||||||
|
@ -275,7 +275,7 @@ const EXPRESS::DataType* EXPRESS::DataType::Parse(const char*& inout,uint64_t li
|
||||||
std::transform(s.begin(),s.end(),s.begin(),&ToLower<char> );
|
std::transform(s.begin(),s.end(),s.begin(),&ToLower<char> );
|
||||||
if (schema->IsKnownToken(s)) {
|
if (schema->IsKnownToken(s)) {
|
||||||
for(cur = t+1;*cur++ != '(';);
|
for(cur = t+1;*cur++ != '(';);
|
||||||
const EXPRESS::DataType* const dt = Parse(cur);
|
const boost::shared_ptr<const EXPRESS::DataType> dt = Parse(cur);
|
||||||
inout = *cur ? cur+1 : cur;
|
inout = *cur ? cur+1 : cur;
|
||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
|
@ -289,11 +289,11 @@ const EXPRESS::DataType* EXPRESS::DataType::Parse(const char*& inout,uint64_t li
|
||||||
|
|
||||||
if (*cur == '*' ) {
|
if (*cur == '*' ) {
|
||||||
inout = cur+1;
|
inout = cur+1;
|
||||||
return new EXPRESS::ISDERIVED();
|
return boost::make_shared<EXPRESS::ISDERIVED>();
|
||||||
}
|
}
|
||||||
else if (*cur == '$' ) {
|
else if (*cur == '$' ) {
|
||||||
inout = cur+1;
|
inout = cur+1;
|
||||||
return new EXPRESS::UNSET();
|
return boost::make_shared<EXPRESS::UNSET>();
|
||||||
}
|
}
|
||||||
else if (*cur == '(' ) {
|
else if (*cur == '(' ) {
|
||||||
// start of an aggregate, further parsing is done by the LIST factory constructor
|
// start of an aggregate, further parsing is done by the LIST factory constructor
|
||||||
|
@ -309,11 +309,11 @@ const EXPRESS::DataType* EXPRESS::DataType::Parse(const char*& inout,uint64_t li
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inout = cur+1;
|
inout = cur+1;
|
||||||
return new EXPRESS::ENUMERATION( std::string(start, static_cast<size_t>(cur-start) ));
|
return boost::make_shared<EXPRESS::ENUMERATION>(std::string(start, static_cast<size_t>(cur-start) ));
|
||||||
}
|
}
|
||||||
else if (*cur == '#' ) {
|
else if (*cur == '#' ) {
|
||||||
// object reference
|
// object reference
|
||||||
return new EXPRESS::ENTITY(strtoul10_64(++cur,&inout));
|
return boost::make_shared<EXPRESS::ENTITY>(strtoul10_64(++cur,&inout));
|
||||||
}
|
}
|
||||||
else if (*cur == '\'' ) {
|
else if (*cur == '\'' ) {
|
||||||
// string literal
|
// string literal
|
||||||
|
@ -331,7 +331,7 @@ const EXPRESS::DataType* EXPRESS::DataType::Parse(const char*& inout,uint64_t li
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inout = cur+1;
|
inout = cur+1;
|
||||||
return new EXPRESS::STRING( std::string(start, static_cast<size_t>(cur-start) ));
|
return boost::make_shared<EXPRESS::STRING>(std::string(start, static_cast<size_t>(cur-start) ));
|
||||||
}
|
}
|
||||||
else if (*cur == '\"' ) {
|
else if (*cur == '\"' ) {
|
||||||
throw STEP::SyntaxError("binary data not supported yet",line);
|
throw STEP::SyntaxError("binary data not supported yet",line);
|
||||||
|
@ -345,7 +345,7 @@ const EXPRESS::DataType* EXPRESS::DataType::Parse(const char*& inout,uint64_t li
|
||||||
// XXX many STEP files contain extremely accurate data, float's precision may not suffice in many cases
|
// XXX many STEP files contain extremely accurate data, float's precision may not suffice in many cases
|
||||||
float f;
|
float f;
|
||||||
inout = fast_atof_move(start,f);
|
inout = fast_atof_move(start,f);
|
||||||
return new EXPRESS::REAL(f);
|
return boost::make_shared<EXPRESS::REAL>(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,14 +358,14 @@ const EXPRESS::DataType* EXPRESS::DataType::Parse(const char*& inout,uint64_t li
|
||||||
++start;
|
++start;
|
||||||
}
|
}
|
||||||
int64_t num = static_cast<int64_t>( strtoul10_64(start,&inout) );
|
int64_t num = static_cast<int64_t>( strtoul10_64(start,&inout) );
|
||||||
return new EXPRESS::INTEGER(neg?-num:num);
|
return boost::make_shared<EXPRESS::INTEGER>(neg?-num:num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
const EXPRESS::LIST* EXPRESS::LIST::Parse(const char*& inout,uint64_t line, const EXPRESS::ConversionSchema* schema /*= NULL*/)
|
boost::shared_ptr<const EXPRESS::LIST> EXPRESS::LIST::Parse(const char*& inout,uint64_t line, const EXPRESS::ConversionSchema* schema /*= NULL*/)
|
||||||
{
|
{
|
||||||
std::auto_ptr<EXPRESS::LIST> list(new EXPRESS::LIST());
|
const boost::shared_ptr<EXPRESS::LIST> list = boost::make_shared<EXPRESS::LIST>();
|
||||||
EXPRESS::LIST::MemberList& members = list->members;
|
EXPRESS::LIST::MemberList& members = list->members;
|
||||||
|
|
||||||
const char* cur = inout;
|
const char* cur = inout;
|
||||||
|
@ -390,7 +390,7 @@ const EXPRESS::LIST* EXPRESS::LIST::Parse(const char*& inout,uint64_t line, cons
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
members.push_back( boost::shared_ptr<const EXPRESS::DataType> (EXPRESS::DataType::Parse(cur,line,schema)));
|
members.push_back( EXPRESS::DataType::Parse(cur,line,schema));
|
||||||
SkipSpaces(cur,&cur);
|
SkipSpaces(cur,&cur);
|
||||||
|
|
||||||
if (*cur != ',') {
|
if (*cur != ',') {
|
||||||
|
@ -402,7 +402,7 @@ const EXPRESS::LIST* EXPRESS::LIST::Parse(const char*& inout,uint64_t line, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
inout = cur+1;
|
inout = cur+1;
|
||||||
return list.release();
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -446,7 +446,6 @@ STEP::LazyObject::~LazyObject()
|
||||||
// make sure the right dtor/operator delete get called
|
// make sure the right dtor/operator delete get called
|
||||||
if (obj) {
|
if (obj) {
|
||||||
delete obj;
|
delete obj;
|
||||||
delete conv_args;
|
|
||||||
}
|
}
|
||||||
else delete[] args;
|
else delete[] args;
|
||||||
}
|
}
|
||||||
|
@ -461,9 +460,10 @@ void STEP::LazyObject::LazyInit() const
|
||||||
throw STEP::TypeError("unknown object type: " + std::string(type),id);
|
throw STEP::TypeError("unknown object type: " + std::string(type),id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* a = args, *acopy = a;
|
const char* acopy = args;
|
||||||
conv_args = EXPRESS::LIST::Parse(acopy,STEP::SyntaxError::LINE_NOT_SPECIFIED,&db.GetSchema());
|
boost::shared_ptr<const EXPRESS::LIST> conv_args = EXPRESS::LIST::Parse(acopy,STEP::SyntaxError::LINE_NOT_SPECIFIED,&db.GetSchema());
|
||||||
delete[] a;
|
delete[] args;
|
||||||
|
args = NULL;
|
||||||
|
|
||||||
// if the converter fails, it should throw an exception, but it should never return NULL
|
// if the converter fails, it should throw an exception, but it should never return NULL
|
||||||
try {
|
try {
|
||||||
|
@ -478,8 +478,5 @@ void STEP::LazyObject::LazyInit() const
|
||||||
|
|
||||||
// store the original id in the object instance
|
// store the original id in the object instance
|
||||||
obj->SetID(id);
|
obj->SetID(id);
|
||||||
|
|
||||||
delete conv_args;
|
|
||||||
conv_args = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue