Sfoglia il codice sorgente

Use of initialisation lists in constructors

mingodad 8 anni fa
parent
commit
6b1d7ec41a

+ 2 - 7
SquiLu/squirrel/sqclass.cpp

@@ -10,14 +10,9 @@
 
 
 
-SQClass::SQClass(SQSharedState *ss,SQClass *base)
+SQClass::SQClass(SQSharedState *ss,SQClass *base):
+    _base(base),_typetag(0),_hook(NULL),_constructoridx(-1),_destructoridx(-1),_udsize(0),_locked(false)
 {
-	_base = base;
-	_typetag = 0;
-	_hook = NULL;
-	_udsize = 0;
-	_locked = false;
-	_constructoridx = _destructoridx = -1;
 	if(_base) {
 		_constructoridx = _base->_constructoridx;
 		_destructoridx = _base->_destructoridx;

+ 3 - 2
SquiLu/squirrel/sqclass.h

@@ -118,15 +118,16 @@ public:
 
 struct SQInstance : public SQDelegable
 {
+private:
 	void Init(SQSharedState *ss);
 	SQInstance(SQSharedState *ss, SQClass *c, SQInteger memsize);
 	SQInstance(SQSharedState *ss, SQInstance *c, SQInteger memsize);
 public:
-	static SQInstance* Create(SQSharedState *ss,SQClass *theclass) {
+	static SQInstance* Create(SQSharedState *ss, SQClass *theclass) {
 
 		SQInteger size = calcinstancesize(theclass);
 		SQInstance *newinst = (SQInstance *)SQ_MALLOC(size);
-		new (newinst) SQInstance(ss, theclass,size);
+		new (newinst) SQInstance(ss, theclass, size);
 		if(theclass->_udsize) {
 			newinst->_userpointer = ((unsigned char *)newinst) + (size - theclass->_udsize);
 		}

+ 5 - 10
SquiLu/squirrel/sqfuncproto.h

@@ -46,16 +46,11 @@ struct SQLocalVarInfo
 {
 	SQLocalVarInfo():_start_op(0),_end_op(0),_pos(0),
         _type(_VAR_ANY),_scope(0) {}
-	SQLocalVarInfo(const SQLocalVarInfo &lvi)
-	{
-		_name=lvi._name;
-		_type_name=lvi._type_name;
-		_start_op=lvi._start_op;
-		_end_op=lvi._end_op;
-		_pos=lvi._pos;
-		_type=lvi._type;
-		_scope=lvi._scope;
-	}
+	SQLocalVarInfo(const SQLocalVarInfo &lvi):
+	    _name(lvi._name),_type_name(lvi._type_name),
+	    _start_op(lvi._start_op),_end_op(lvi._end_op),
+	    _pos(lvi._pos),_type(lvi._type),_scope(lvi._scope)
+	{}
 	SQObjectPtr _name;
 	SQObjectPtr _type_name;
 	SQUnsignedInteger _start_op;

+ 4 - 16
SquiLu/squirrel/sqfuncstate.cpp

@@ -28,25 +28,13 @@ void DumpLiteral(SQObjectPtr &o)
 	}
 }
 
-SQFuncState::SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc efunc,void *ed)
+SQFuncState::SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc efunc,void *ed):
+    _returnexp(0),_stacksize(0),_nliterals(0),_parent(parent),_lastline(0),_traps(0),
+    _outers(0),_optimization(true),_varparams(false),_bgenerator(false),_sharedstate(ss),
+    _errfunc(efunc),_errtarget(ed),_ss(ss)
 {
-		_nliterals = 0;
 		_literals = SQTable::Create(ss,0);
 		_strings =  SQTable::Create(ss,0);
-		_sharedstate = ss;
-		_lastline = 0;
-		_optimization = true;
-		_parent = parent;
-		_stacksize = 0;
-		_traps = 0;
-		_returnexp = 0;
-		_varparams = false;
-		_errfunc = efunc;
-		_errtarget = ed;
-		_bgenerator = false;
-		_outers = 0;
-		_ss = ss;
-
 }
 
 void SQFuncState::Error(const SQChar *err)

+ 1 - 1
SquiLu/squirrel/sqobject.h

@@ -88,7 +88,7 @@ struct SQRefCounted
 {
 	SQUnsignedInteger _uiRef;
 	struct SQWeakRef *_weakref;
-	SQRefCounted() { _uiRef = 0; _weakref = NULL; }
+	SQRefCounted(): _uiRef(0), _weakref(NULL) {}
 	virtual ~SQRefCounted();
 	SQWeakRef *GetWeakRef(SQObjectType type);
 	virtual void Release()=0;

+ 3 - 5
SquiLu/squirrel/sqopcodes.h

@@ -120,11 +120,9 @@ struct SQInstruction
 {
 	SQInstruction(){};
 	SQInstruction(SQOpcode _op,SQInteger a0=0,SQInteger a1=0,SQInteger a2=0,SQInteger a3=0)
-	{	op = (unsigned char)_op;
-		_arg0 = (unsigned char)a0;_arg1 = (SQInt32)a1;
-		_arg2 = (unsigned char)a2;_arg3 = (unsigned char)a3;
-	}
-
+        : _arg1((SQInt32)a1),op((unsigned char)_op),_arg0((unsigned char)a0),
+	    _arg2((unsigned char)a2),_arg3((unsigned char)a3)
+    {}
 
 	SQInt32 _arg1;
 	unsigned char op;

+ 1 - 3
SquiLu/squirrel/sqstate.cpp

@@ -608,11 +608,9 @@ void RefTable::AllocNodes(SQUnsignedInteger size)
 * http://www.lua.org/source/4.0.1/src_lstring.c.html
 */
 
-SQStringTable::SQStringTable(SQSharedState *ss)
+SQStringTable::SQStringTable(SQSharedState *ss):_slotused(0), _sharedstate(ss)
 {
-	_sharedstate = ss;
 	AllocNodes(4);
-	_slotused = 0;
 }
 
 SQStringTable::~SQStringTable()

+ 1 - 2
SquiLu/squirrel/sqtable.cpp

@@ -7,12 +7,11 @@ see copyright notice in squirrel.h
 #include "sqfuncproto.h"
 #include "sqclosure.h"
 
-SQTable::SQTable(SQSharedState *ss,SQInteger nInitialSize)
+SQTable::SQTable(SQSharedState *ss,SQInteger nInitialSize):_usednodes(0)
 {
 	SQInteger pow2size=MINPOWER2;
 	while(nInitialSize>pow2size)pow2size=pow2size<<1;
 	AllocNodes(pow2size);
-	_usednodes = 0;
 	_delegate = NULL;
 	INIT_CHAIN();
 	ADD_TO_CHAIN(&_sharedstate->_gc_chain,this);

+ 19 - 19
SquiLu/squirrel/sqtable.h

@@ -27,7 +27,7 @@ struct SQTable : public SQDelegable
 private:
 	struct _HashNode
 	{
-		_HashNode() { next = NULL; }
+		_HashNode():next(NULL) {}
 		SQObjectPtr val;
 		SQObjectPtr key;
 		_HashNode *next;
@@ -73,24 +73,24 @@ public:
 		}while((n = n->next));
 		return NULL;
 	}
-	//for compiler use
-	inline bool GetStr(const SQChar* key,SQInteger keylen,SQObjectPtr &val)
-	{
-		SQHash hash = _hashstr(key,keylen);
-		_HashNode *n = &_nodes[hash & (_numofnodes - 1)];
-		_HashNode *res = NULL;
-		do{
-			if(type(n->key) == OT_STRING && (scstrcmp(_stringval(n->key),key) == 0)){
-				res = n;
-				break;
-			}
-		}while((n = n->next));
-		if (res) {
-			val = _realval(res->val);
-			return true;
-		}
-		return false;
-	}
+	//for compiler use
+	inline bool GetStr(const SQChar* key,SQInteger keylen,SQObjectPtr &val)
+	{
+		SQHash hash = _hashstr(key,keylen);
+		_HashNode *n = &_nodes[hash & (_numofnodes - 1)];
+		_HashNode *res = NULL;
+		do{
+			if(type(n->key) == OT_STRING && (scstrcmp(_stringval(n->key),key) == 0)){
+				res = n;
+				break;
+			}
+		}while((n = n->next));
+		if (res) {
+			val = _realval(res->val);
+			return true;
+		}
+		return false;
+	}
 	bool Get(const SQObjectPtr &key,SQObjectPtr &val);
 	bool Exists(const SQObjectPtr &key);
 	void Remove(const SQObjectPtr &key);

+ 8 - 8
SquiLu/squirrel/squserdata.h

@@ -4,7 +4,9 @@
 
 struct SQUserData : SQDelegable
 {
-	SQUserData(SQSharedState *ss){ _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); }
+	SQUserData(SQSharedState *ss, SQInteger size=0):_size(size),_hook(NULL),_typetag(0) {
+	    _delegate = 0; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this);
+    }
 	~SQUserData()
 	{
 		REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this);
@@ -13,9 +15,7 @@ struct SQUserData : SQDelegable
 	static SQUserData* Create(SQSharedState *ss, SQInteger size)
 	{
 		SQUserData* ud = (SQUserData*)SQ_MALLOC(sq_aligning(sizeof(SQUserData))+size);
-		new (ud) SQUserData(ss);
-		ud->_size = size;
-		ud->_typetag = 0;
+		new (ud) SQUserData(ss, size);
 		return ud;
 	}
 #ifndef NO_GARBAGE_COLLECTOR
@@ -24,11 +24,11 @@ struct SQUserData : SQDelegable
 	SQObjectType GetType(){ return OT_USERDATA;}
 #endif
 	void Release() {
-		if (_hook) {
+		if (_hook) {
 #if !defined(NO_GARBAGE_COLLECTOR) && defined(SQ_WITH_DELAYED_RELEASE_HOOKS)
-		    _sharedstate->AddDelayedReleaseHook(_hook, (SQUserPointer)sq_aligning(this + 1), _size);
-#else
-		    _hook((SQUserPointer)sq_aligning(this + 1),_size, 0);
+		    _sharedstate->AddDelayedReleaseHook(_hook, (SQUserPointer)sq_aligning(this + 1), _size);
+#else
+		    _hook((SQUserPointer)sq_aligning(this + 1),_size, 0);
 #endif
 		}
 		SQInteger tsize = _size;

+ 3 - 1
SquiLu/squirrel/sqvm.h

@@ -22,7 +22,9 @@ void sq_base_register(HSQUIRRELVM v);
 
 struct SQExceptionTrap{
 	SQExceptionTrap() {}
-	SQExceptionTrap(SQInteger ss, SQInteger stackbase,SQInstruction *ip, SQInteger ex_target){ _stacksize = ss; _stackbase = stackbase; _ip = ip; _extarget = ex_target;}
+	SQExceptionTrap(SQInteger ss, SQInteger stackbase,SQInstruction *ip, SQInteger ex_target):
+	    _stackbase(stackbase),_stacksize(ss),_ip(ip),_extarget(ex_target)
+	{}
 	SQExceptionTrap(const SQExceptionTrap &et) { (*this) = et;	}
 	SQInteger _stackbase;
 	SQInteger _stacksize;