[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-devel] Patch GAV_aux.cc
From: |
Valéry Raulet |
Subject: |
[certi-devel] Patch GAV_aux.cc |
Date: |
Tue, 26 Nov 2002 09:40:02 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2b) Gecko/20021016 |
Bonjour,
j'ai fait des modifications au fichier GAV_aux.cc : a prendre ou à
laisser, comme vous voulez
-> ajout de inline dans les fonctions avec seulement un return
-> changement de la recopie for(unsigned int i=0; ...) buff[i] =
tmp->_value[i]; par un memcpy()
-> résolution de deux types de fuites mémoire :
-> lors d'un remove d'AttributeHandleSet, ...
-> lors d'un empty d'AttributeHandleSet, ...
Dites moi ce que vous en pensez, merci.
Valéry Raulet.
--- certi-3.0.1/libCERTI/GAV_aux.cc 2002-11-22 01:52:56.000000000 +0100
+++ certi-3.0.1_devel/libCERTI/GAV_aux.cc 2002-11-26 09:28:29.000000000
+0100
@@ -51,7 +51,7 @@
-ULong AttributeHandleValuePairSet::size() const
+inline ULong AttributeHandleValuePairSet::size() const
{
return _size;
}
@@ -105,8 +105,9 @@
for(unsigned int j=0; j<i; j++) {
tmp = tmp->_next;
}
- for(unsigned int i=0; i<tmp->_valuelength; i++) buff[i] = tmp->_value[i];
+ // for(unsigned int i=0; i<tmp->_valuelength; i++) buff[i] =
tmp->_value[i];
// strcpy(buff,tmp->_value);
+ memcpy(buff, tmp->_value, tmp->_valuelength);
valueLength = tmp->_valuelength;
}
@@ -133,14 +134,14 @@
throw ArrayIndexOutOfBounds();
}
-TransportType
+inline TransportType
AttributeHandleValuePairSet::getTransportType(ULong) const
throw(ArrayIndexOutOfBounds, InvalidHandleValuePairSetContext)
{
return _transport;
}
-OrderType
+inline OrderType
AttributeHandleValuePairSet::getOrderType(ULong) const
throw(ArrayIndexOutOfBounds, InvalidHandleValuePairSetContext)
{
@@ -167,8 +168,8 @@
newNode->_next = _head;
newNode->_handle = h;
newNode->_valuelength = valueLength;
- for(unsigned int i=0; i < valueLength; i++) newNode->_value[i] = buff[i];
- // strcpy(newNode->_value,buff);
+ // for(unsigned int i=0; i < valueLength; i++) newNode->_value[i] =
buff[i]; // strcpy(newNode->_value,buff);
+ memcpy(newNode->_value, buff, valueLength);
_head = newNode;
_size++;
}
@@ -182,20 +183,24 @@
AttributeHandleValuePair *prec = _head;
for(unsigned int j=0; j<_size; j++) {
- if(tmp->_handle == h) {
- if(j==0) {
- _head = _head->_next;
- _size--;
+ if(tmp->_handle == h)
+ {
+ if(j==0)
+ {
+ _head = _head->_next;
+ }
+ else
+ {
+ prec->_next = tmp->_next;
+ }
+
+ delete tmp;
+ _size--;
+ return;
}
- else {
- prec->_next = tmp->_next;
- _size--;
- }
- }
- else {
- prec = tmp;
- tmp = tmp->_next;
- }
+
+ prec = tmp;
+ tmp = tmp->_next;
}
throw ArrayIndexOutOfBounds();
@@ -213,6 +218,16 @@
void AttributeHandleValuePairSet::empty()
// Empty the Set without deallocating space.
{
+ AttributeHandleValuePair * tmp = _head;
+ AttributeHandleValuePair * next = _head->_next;
+ for (unsigned int i = 0 ; i < _size-1 ; i++)
+ {
+ delete tmp;
+ tmp = next;
+ next = next->_next;
+ }
+ delete tmp;
+
_head =(AttributeHandleValuePair *)NULL;
_size = 0;
}
@@ -249,7 +264,7 @@
ahvps->_order = RECEIVE;
ahvps->_transport = RELIABLE;
ahvps->_head =(AttributeHandleValuePair *)NULL;
- ahvps->_size = 0;
+ ahvps->_size = 0;
return ahvps;
}
@@ -271,7 +286,7 @@
// AttributeHandleSet
//-----------------------------------------------------------------------
-ULong AttributeHandleSet::size() const
+inline ULong AttributeHandleSet::size() const
{
return _size;
}
@@ -312,20 +327,24 @@
HandlePair *prec = _head;
for(unsigned int j=0; j<_size; j++) {
- if(tmp->_handle == h) {
- if(j==0) {
- _head = _head->_next;
- _size--;
+ if(tmp->_handle == h)
+ {
+ if(j==0)
+ {
+ _head = _head->_next;
+ }
+ else
+ {
+ prec->_next = tmp->_next;
+ }
+
+ delete tmp;
+ _size--;
+ return;
}
- else {
- prec->_next = tmp->_next;
- _size--;
- }
- }
- else {
- prec = tmp;
- tmp = tmp->_next;
- }
+
+ prec = tmp;
+ tmp = tmp->_next;
}
throw AttributeNotDefined();
@@ -333,16 +352,23 @@
void AttributeHandleSet::empty() // Empty the Set
{
+ HandlePair * tmp = _head;
+ HandlePair * next = _head->_next;
+ for (unsigned int i = 0 ; i < _size-1 ; i++)
+ {
+ delete tmp;
+ tmp = next;
+ next = next->_next;
+ }
+ delete tmp;
+
_head =(HandlePair *)NULL;
_size = 0;
}
-Boolean AttributeHandleSet::isEmpty() const //is set empty?
+inline Boolean AttributeHandleSet::isEmpty() const //is set empty?
{
-if(_size == 0)
- return RTI_TRUE;
-else
- return RTI_FALSE;
+ return ((_size == 0) ? RTI_TRUE : RTI_FALSE);
}
Boolean AttributeHandleSet::isMember(AttributeHandle h) const
@@ -394,7 +420,7 @@
// ParameterHandleValuePairSet
//-----------------------------------------------------------------------
-ULong ParameterHandleValuePairSet::size() const
+inline ULong ParameterHandleValuePairSet::size() const
{
return _size;
}
@@ -448,8 +474,9 @@
for(unsigned int j=0; j<i; j++) {
tmp = tmp->_next;
}
- for(unsigned int i=0; i<tmp->_valuelength; i++) buff[i] = tmp->_value[i];
+ //for(unsigned int i=0; i<tmp->_valuelength; i++) buff[i] = tmp->_value[i];
// strcpy(buff,tmp->_value);
+ memcpy(buff, tmp->_value, tmp->_valuelength);
valueLength = tmp->_valuelength;
}
}
@@ -474,13 +501,13 @@
throw ArrayIndexOutOfBounds();
}
-TransportType ParameterHandleValuePairSet::getTransportType(void) const
+inline TransportType ParameterHandleValuePairSet::getTransportType(void) const
throw( InvalidHandleValuePairSetContext)
{
return _transport;
}
-OrderType ParameterHandleValuePairSet::getOrderType(void) const
+inline OrderType ParameterHandleValuePairSet::getOrderType(void) const
throw( InvalidHandleValuePairSetContext)
{
return _order;
@@ -506,19 +533,43 @@
newNode->_next = _head;
newNode->_handle = h;
newNode->_valuelength = valueLength;
- for(unsigned int i=0; i < valueLength; i++) newNode->_value[i] = buff[i];
-
+ // for(unsigned int i=0; i < valueLength; i++) newNode->_value[i] = buff[i];
// strcpy(newNode->_value,buff);
+ memcpy(newNode->_value, buff, valueLength);
_head = newNode;
_size++;
}
// not guaranteed safe while iterating
void
-ParameterHandleValuePairSet::remove(Handle)
+ParameterHandleValuePairSet::remove(Handle h)
throw(ArrayIndexOutOfBounds)
{
- _size--;
+ ParameterHandleValuePair *tmp = _head;
+ ParameterHandleValuePair *prec = _head;
+
+ for(unsigned int j=0; j<_size; j++) {
+ if(tmp->_handle == h)
+ {
+ if(j==0)
+ {
+ _head = _head->_next;
+ }
+ else
+ {
+ prec->_next = tmp->_next;
+ }
+
+ delete tmp;
+ _size--;
+ return;
+ }
+
+ prec = tmp;
+ tmp = tmp->_next;
+ }
+
+ throw ArrayIndexOutOfBounds();
}
void
@@ -534,7 +585,17 @@
void
ParameterHandleValuePairSet::empty(void)
{
- _head =(ParameterHandleValuePair *)NULL;
+ ParameterHandleValuePair * tmp = _head;
+ ParameterHandleValuePair * next = _head->_next;
+ for (unsigned int i = 0 ; i < _size-1 ; i++)
+ {
+ delete tmp;
+ tmp = next;
+ next = next->_next;
+ }
+ delete tmp;
+
+ _head = (ParameterHandleValuePair *)NULL;
_size = 0;
}
- [certi-devel] Patch GAV_aux.cc,
Valéry Raulet <=