[10982] Optimize memory usage of Field class used in DB code. Should also slightly speedup server startup time.

Signed-off-by: Ambal <pogrebniak@gala.net>
This commit is contained in:
Ambal 2011-01-07 18:53:48 +02:00
parent f56ae22ed9
commit b89e531fee
3 changed files with 11 additions and 53 deletions

View file

@ -16,50 +16,5 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "DatabaseEnv.h"
//#include "DatabaseEnv.h"
Field::Field() :
mValue(NULL), mType(DB_TYPE_UNKNOWN)
{
}
Field::Field(Field &f)
{
const char *value;
value = f.GetString();
if (value && (mValue = new char[strlen(value) + 1]))
strcpy(mValue, value);
else
mValue = NULL;
mType = f.GetType();
}
Field::Field(const char *value, enum Field::DataTypes type) :
mType(type)
{
if (value && (mValue = new char[strlen(value) + 1]))
strcpy(mValue, value);
else
mValue = NULL;
}
Field::~Field()
{
if(mValue) delete [] mValue;
}
void Field::SetValue(const char *value)
{
if(mValue) delete [] mValue;
if (value)
{
mValue = new char[strlen(value) + 1];
strcpy(mValue, value);
}
else
mValue = NULL;
}

View file

@ -34,11 +34,10 @@ class Field
DB_TYPE_BOOL = 0x04
};
Field();
Field(Field &f);
Field(const char *value, enum DataTypes type);
Field() : mValue(NULL), mType(DB_TYPE_UNKNOWN) {}
Field(const char *value, enum DataTypes type) : mType(type) { mValue = const_cast<char * >(value); }
~Field();
~Field() {}
enum DataTypes GetType() const { return mType; }
bool IsNULL() const { return mValue == NULL; }
@ -68,10 +67,14 @@ class Field
}
void SetType(enum DataTypes type) { mType = type; }
void SetValue(const char *value);
//no need for memory allocations to store resultset field strings
//all we need is to cache pointers returned by different DBMS APIs
void SetValue(const char *value) { mValue = const_cast<char * >(value); };
private:
Field(Field &f);
Field& operator=(const Field& );
char *mValue;
enum DataTypes mType;
};

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10981"
#define REVISION_NR "10982"
#endif // __REVISION_NR_H__