[MOAB-dev] r1578 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Mon Feb 4 10:26:00 CST 2008
Author: kraftche
Date: 2008-02-04 10:23:40 -0600 (Mon, 04 Feb 2008)
New Revision: 1578
Modified:
MOAB/trunk/TagInfo.cpp
MOAB/trunk/TagInfo.hpp
Log:
o Don't use VarLenTag structure for Default and Mesh values for tags.
Using it for the default value introduces two extra branches for
all tag queries. That's not much, but it can be eliminated for no
performance cost. Change mesh value just to keep it consistant with
default value.
o Re-order data members of TagInfo to make it a little more compact.
Modified: MOAB/trunk/TagInfo.cpp
===================================================================
--- MOAB/trunk/TagInfo.cpp 2008-02-01 23:39:12 UTC (rev 1577)
+++ MOAB/trunk/TagInfo.cpp 2008-02-04 16:23:40 UTC (rev 1578)
@@ -17,6 +17,78 @@
{
mTagName.clear();
isValid = false;
- mDefaultValue.clear();
- mMeshValue.clear();
+ free( mMeshValue );
+ free( mDefaultValue );
+ mDefaultValue = mMeshValue = 0;
+ mDefaultValueSize = mMeshValueSize = 0;
}
+
+
+TagInfo::TagInfo( const TagInfo& copy )
+ : mDefaultValue(0),
+ mMeshValue(0),
+ mDefaultValueSize(copy.mDefaultValueSize),
+ mMeshValueSize(copy.mMeshValueSize),
+ mDataSize(copy.mDataSize),
+ dataType(copy.dataType),
+ mTagName(copy.mTagName),
+ isValid(copy.isValid)
+{
+ if (mDefaultValueSize) {
+ mDefaultValue = malloc( mDefaultValueSize );
+ memcpy( mDefaultValue, copy.mDefaultValue, mDefaultValueSize );
+ }
+ if (mMeshValueSize) {
+ mMeshValue = malloc( mMeshValueSize );
+ memcpy( mMeshValue, copy.mMeshValue, mMeshValueSize );
+ }
+}
+
+TagInfo& TagInfo::operator=( const TagInfo& copy )
+{
+ if (copy.mDefaultValue) {
+ if (mDefaultValueSize != copy.mDefaultValueSize)
+ mDefaultValue = realloc( mDefaultValue,copy.mDefaultValueSize);
+ mDefaultValueSize = copy.mDefaultValueSize;
+ memcpy( mDefaultValue, copy.mDefaultValue, copy.mDefaultValueSize );
+ }
+ else if (mDefaultValue) {
+ free( mDefaultValue );
+ mDefaultValue = 0;
+ mDefaultValueSize = 0;
+ }
+
+ if (copy.mMeshValue) {
+ if (mMeshValueSize != copy.mMeshValueSize)
+ mMeshValue = realloc( mMeshValue,copy.mMeshValueSize);
+ mMeshValueSize = copy.mMeshValueSize;
+ memcpy( mMeshValue, copy.mMeshValue, copy.mMeshValueSize );
+ }
+ else if (mMeshValue) {
+ free( mMeshValue );
+ mMeshValue = 0;
+ mMeshValueSize = 0;
+ }
+
+ mDataSize = copy.mDataSize;
+ dataType = copy.dataType;
+ mTagName = copy.mTagName;
+ isValid = copy.isValid;
+ return *this;
+}
+
+void TagInfo::set_mesh_value( const void* data, int size )
+{
+ if (mMeshValueSize != size) {
+ mMeshValueSize = size;
+ mMeshValue = realloc( mMeshValue, size );
+ }
+ memcpy( mMeshValue, data, size );
+}
+
+ //! remove mesh value
+void TagInfo::remove_mesh_value()
+{
+ free( mMeshValue );
+ mMeshValueSize = 0;
+}
Modified: MOAB/trunk/TagInfo.hpp
===================================================================
--- MOAB/trunk/TagInfo.hpp 2008-02-01 23:39:12 UTC (rev 1577)
+++ MOAB/trunk/TagInfo.hpp 2008-02-04 16:23:40 UTC (rev 1578)
@@ -2,11 +2,10 @@
#define TAG_INFO_HPP
#include "MBTypes.h"
-#include "VarLenTag.hpp"
#include <string>
-#include <string.h>
-#include <assert.h>
+#include <string.h> /* memcpy */
+#include <stdlib.h> /* realloc & free */
// ! stores information about a tag
class TagInfo
@@ -14,10 +13,14 @@
public:
//! constructor
- TagInfo() : mTagName(""),
+ TagInfo() : mDefaultValue(0),
+ mMeshValue(0),
+ mDefaultValueSize(0),
+ mMeshValueSize(0),
mDataSize(0),
- isValid(false),
- dataType(MB_TYPE_OPAQUE)
+ dataType(MB_TYPE_OPAQUE),
+ mTagName(""),
+ isValid(false)
{}
//! constructor that takes all parameters
@@ -27,6 +30,12 @@
const void * default_value,
int default_value_size);
+ TagInfo( const TagInfo& copy );
+
+ inline ~TagInfo();
+
+ TagInfo& operator=( const TagInfo& copy );
+
//! set the name of the tag
void set_name( const std::string& name) { mTagName = name; }
@@ -40,24 +49,24 @@
int get_size() const { return mDataSize; }
//! get length of default value
- int default_value_size() const { return mDefaultValue.size(); }
+ int default_value_size() const { return mDefaultValueSize; }
//! get the default data
const void *default_value() const
- { return mDefaultValue.size() ? mDefaultValue.data() : 0;}
+ { return mDefaultValue; }
//! set mesh value
void set_mesh_value( const void* data, int size );
//! get mesh value
- int get_mesh_value_size() const { return mMeshValue.size(); }
+ int get_mesh_value_size() const { return mMeshValueSize; }
//! get mesh value
const void* get_mesh_value() const
- { return mMeshValue.size() ? mMeshValue.data() : 0; }
+ { return mMeshValue; }
//! remove mesh value
- void remove_mesh_value() { mMeshValue.clear(); }
+ void remove_mesh_value();
inline MBDataType get_data_type() const { return dataType; }
@@ -72,24 +81,30 @@
MBErrorCode reserve_mesh_tag_id( int& id_out );
- //! stores the tag name
- std::string mTagName;
+ //! stores the default data, if any
+ void* mDefaultValue;
+
+ //! store the mesh value, if any
+ void* mMeshValue;
+
+ //! Size of mDefaultValue and mMeshValue, in bytes
+ //! NOTE: These sizes differ from mDataSize in two cases:
+ //! a) Variable-length tags
+ //! b) Bit tags (where mDataSize is bits, not bytes.)
+ int mDefaultValueSize, mMeshValueSize;
//! stores the size of the data for this tag
int mDataSize;
+ //! type of tag data
+ MBDataType dataType;
+
+ //! stores the tag name
+ std::string mTagName;
+
//! flag to mark unused entries
bool isValid;
- //! stores the default data, if any
- VarLenTag mDefaultValue;
-
- //! store the mesh value, if any
- VarLenTag mMeshValue;
-
- //! type of tag data
- MBDataType dataType;
-
};
inline TagInfo::TagInfo( const char* name,
@@ -97,19 +112,27 @@
MBDataType type,
const void* default_value,
int default_value_size)
- : mTagName( name ),
- mDataSize( size ),
- isValid( true ),
- mDefaultValue( default_value_size, default_value ),
- dataType( type )
+ : mDefaultValue(0),
+ mMeshValue(0),
+ mDefaultValueSize(default_value_size),
+ mMeshValueSize(0),
+ mDataSize(size),
+ dataType(type),
+ mTagName(name),
+ isValid(true)
{
+ if (default_value) {
+ mDefaultValue = malloc( mDefaultValueSize );
+ memcpy( mDefaultValue, default_value, mDefaultValueSize );
+ }
}
-
-inline void TagInfo::set_mesh_value( const void* data, int size )
+inline TagInfo::~TagInfo()
{
- // if tag is not variable-length, then size must be tag size
- mMeshValue.set( data, size );
+ free( mDefaultValue );
+ free( mMeshValue );
+ mDefaultValue = mMeshValue = 0;
+ mDefaultValueSize = mMeshValueSize = 0;
}
#endif
More information about the moab-dev
mailing list