mirror of
https://github.com/mangosfour/server.git
synced 2025-12-17 16:37:00 +00:00
[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:
parent
f56ae22ed9
commit
b89e531fee
3 changed files with 11 additions and 53 deletions
|
|
@ -16,50 +16,5 @@
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,10 @@ class Field
|
||||||
DB_TYPE_BOOL = 0x04
|
DB_TYPE_BOOL = 0x04
|
||||||
};
|
};
|
||||||
|
|
||||||
Field();
|
Field() : mValue(NULL), mType(DB_TYPE_UNKNOWN) {}
|
||||||
Field(Field &f);
|
Field(const char *value, enum DataTypes type) : mType(type) { mValue = const_cast<char * >(value); }
|
||||||
Field(const char *value, enum DataTypes type);
|
|
||||||
|
|
||||||
~Field();
|
~Field() {}
|
||||||
|
|
||||||
enum DataTypes GetType() const { return mType; }
|
enum DataTypes GetType() const { return mType; }
|
||||||
bool IsNULL() const { return mValue == NULL; }
|
bool IsNULL() const { return mValue == NULL; }
|
||||||
|
|
@ -68,10 +67,14 @@ class Field
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetType(enum DataTypes type) { mType = type; }
|
void SetType(enum DataTypes type) { mType = type; }
|
||||||
|
//no need for memory allocations to store resultset field strings
|
||||||
void SetValue(const char *value);
|
//all we need is to cache pointers returned by different DBMS APIs
|
||||||
|
void SetValue(const char *value) { mValue = const_cast<char * >(value); };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Field(Field &f);
|
||||||
|
Field& operator=(const Field& );
|
||||||
|
|
||||||
char *mValue;
|
char *mValue;
|
||||||
enum DataTypes mType;
|
enum DataTypes mType;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10981"
|
#define REVISION_NR "10982"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue