Skip to content

Commit

Permalink
Revert "Found a bug in ForInfoListT object: contrary to its intent, t…
Browse files Browse the repository at this point in the history
…he loop number did not start at 0 but at 32 (the initialized defulat size), and would be constantly increasing in size at each new level of nested loop. May even had an incidence on the loop speed."

This reverts commit ebfa961.
  • Loading branch information
GillesDuvert committed Jul 8, 2024
1 parent 8a15672 commit 2b3269d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
7 changes: 2 additions & 5 deletions src/dpro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
extern bool posixpaths;
}
#endif

#define MAX_LOOPS_NUMBER 32

typedef struct _SCC_STRUCT_ { //semicompiled code, small memory imprint (instead of a copy of the DNodes)
u_int nodeType = 0;
u_int ligne = 0;
Expand Down Expand Up @@ -595,8 +592,8 @@ class DPro: public DSubUD
{
public:
// for main function, not inserted into proList
// should be fine (way too much): MAX_LOOPS_NUMBER (32?) NESTED loops in $MAIN$ (elswhere: unlimited)
DPro(): DSubUD("$MAIN$","","") { this->nForLoops = MAX_LOOPS_NUMBER;}
// should be fine (way too much): 32 NESTED loops in $MAIN$ (elswhere: unlimited)
DPro(): DSubUD("$MAIN$","","") { this->nForLoops = 32;}

DPro(const std::string& n,const std::string& o="",const std::string& f=""):
DSubUD(n,o,f)
Expand Down
6 changes: 3 additions & 3 deletions src/envt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ EnvUDT::EnvUDT( ProgNodeP cN, BaseGDL* self,

DSubUD* proUD=static_cast<DSubUD*>(pro);

forLoopInfo.InitSize(proUD->NForLoops());
forLoopInfo.InitSize( proUD->NForLoops());

SizeT envSize;
// SizeT keySize;
Expand Down Expand Up @@ -264,7 +264,7 @@ EnvUDT::EnvUDT( BaseGDL* self, ProgNodeP cN, const string& parent, CallContext l

DSubUD* proUD=static_cast<DSubUD*>(pro);

forLoopInfo.InitSize(proUD->NForLoops());
forLoopInfo.InitSize( proUD->NForLoops());

SizeT envSize=proUD->var.size();
parIx=proUD->key.size();
Expand Down Expand Up @@ -318,7 +318,7 @@ EnvUDT::EnvUDT( ProgNodeP callingNode_, DSubUD* newPro, DObjGDL** self):

DSubUD* proUD= newPro; //static_cast<DSubUD*>(pro);

forLoopInfo.InitSize(proUD->NForLoops());
forLoopInfo.InitSize( proUD->NForLoops());

SizeT envSize;
// SizeT keySize;
Expand Down
31 changes: 11 additions & 20 deletions src/envt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,12 @@ template< typename T, SizeT defaultLength> class ForInfoListT
private:
T* eArr;
char buf[defaultLength * sizeof(T)]; // prevent constructor calls
SizeT currentMaxLength;
SizeT sz;

public:

ForInfoListT(): eArr( reinterpret_cast<T*>(buf)), sz( 0)
{
currentMaxLength=defaultLength;
{
}

~ForInfoListT()
Expand All @@ -397,51 +395,42 @@ template< typename T, SizeT defaultLength> class ForInfoListT
// must be called before access
void InitSize( SizeT s)
{
// std::cerr<<this<<": InitSize("<<s<<")\n";
assert( sz == 0);
if( s == 0)
return;
sz = 0;
if( s <= currentMaxLength) //initialise currentMaxLength objects
sz = s;
if( s < defaultLength)
{
for( SizeT i=0; i<currentMaxLength; ++i)
for( SizeT i=0; i<s; ++i)
eArr[ i].Init();
return;
}
eArr = new T[ s]; // constructor called
currentMaxLength=s;
}
// only needed for EXECUTE
void resize( SizeT s)
{
// std::cerr<<this<<": resize("<<s<<"): ";
if( s == sz) {
// std::cerr<<" == "<<sz<<": return.\n";
if( s == sz)
return;
}
if( s < sz) // shrink
{
// std::cerr << " < " << sz << ": shrink.\n";
for( SizeT i=s; i<sz; ++i)
eArr[ i].ClearInit(); // in case eArr was allocated
sz = s;
return;
}
// s > sz -> grow
if( s <= currentMaxLength && eArr == reinterpret_cast<T*>(buf))
if( s <= defaultLength && eArr == reinterpret_cast<T*>(buf))
{
// std::cerr << " > " << sz << " but <= currentMaxLength : grow.\n";
for( SizeT i=sz; i<s; ++i)
eArr[ i].Init();
sz = s;
return;
}
// this should never happen (or only in extreme rarely cases)
// the performance will go down
// s > currentMaxLength
// std::cerr << " > " << sz << " and > currentMaxLength : should not happen.\n";
// s > defaultLength
T* newArr = new T[ s]; // ctor called
currentMaxLength=s;
if( eArr != reinterpret_cast<T*>(buf))
{
for( SizeT i=0; i<sz; ++i)
Expand All @@ -462,7 +451,7 @@ template< typename T, SizeT defaultLength> class ForInfoListT
sz = s;
}
// T operator[]( SizeT i) const { assert( i<sz); return eArr[i];}
T& operator[]( SizeT i) { assert( i<currentMaxLength); return eArr[i];}
T& operator[]( SizeT i) { assert( i<sz); return eArr[i];}
SizeT size() const { return sz;}
iterator begin() const { return &eArr[0];}
iterator end() const { return &eArr[sz];}
Expand All @@ -474,6 +463,7 @@ template< typename T, SizeT defaultLength> class ForInfoListT
};



// for UD subroutines (written in GDL) ********************************
class EnvUDT: public EnvBaseT
{
Expand All @@ -491,7 +481,8 @@ class EnvUDT: public EnvBaseT
};

private:
ForInfoListT<ForLoopInfoT, MAX_LOOPS_NUMBER> forLoopInfo; //defaults to $MAIN$ values in dpro.hpp
ForInfoListT<ForLoopInfoT, 32> forLoopInfo;
// std::vector<ForLoopInfoT> forLoopInfo;

ProgNodeP ioError;
DLong onError; // on_error setting
Expand Down

0 comments on commit 2b3269d

Please sign in to comment.