Skip to content

Commit 926c7a2

Browse files
authored
Revert commit ebfa961 and close #1849 (#1851)
1 parent 8a15672 commit 926c7a2

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

src/dpro.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
extern bool posixpaths;
3636
}
3737
#endif
38-
39-
#define MAX_LOOPS_NUMBER 32
40-
4138
typedef struct _SCC_STRUCT_ { //semicompiled code, small memory imprint (instead of a copy of the DNodes)
4239
u_int nodeType = 0;
4340
u_int ligne = 0;
@@ -595,8 +592,8 @@ class DPro: public DSubUD
595592
{
596593
public:
597594
// for main function, not inserted into proList
598-
// should be fine (way too much): MAX_LOOPS_NUMBER (32?) NESTED loops in $MAIN$ (elswhere: unlimited)
599-
DPro(): DSubUD("$MAIN$","","") { this->nForLoops = MAX_LOOPS_NUMBER;}
595+
// should be fine (way too much): 32 NESTED loops in $MAIN$ (elswhere: unlimited)
596+
DPro(): DSubUD("$MAIN$","","") { this->nForLoops = 32;}
600597

601598
DPro(const std::string& n,const std::string& o="",const std::string& f=""):
602599
DSubUD(n,o,f)

src/envt.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ EnvUDT::EnvUDT( ProgNodeP cN, BaseGDL* self,
208208

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

211-
forLoopInfo.InitSize(proUD->NForLoops());
211+
forLoopInfo.InitSize( proUD->NForLoops());
212212

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

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

267-
forLoopInfo.InitSize(proUD->NForLoops());
267+
forLoopInfo.InitSize( proUD->NForLoops());
268268

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

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

321-
forLoopInfo.InitSize(proUD->NForLoops());
321+
forLoopInfo.InitSize( proUD->NForLoops());
322322

323323
SizeT envSize;
324324
// SizeT keySize;

src/envt.hpp

+11-20
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,12 @@ template< typename T, SizeT defaultLength> class ForInfoListT
372372
private:
373373
T* eArr;
374374
char buf[defaultLength * sizeof(T)]; // prevent constructor calls
375-
SizeT currentMaxLength;
376375
SizeT sz;
377376

378377
public:
379378

380379
ForInfoListT(): eArr( reinterpret_cast<T*>(buf)), sz( 0)
381-
{
382-
currentMaxLength=defaultLength;
380+
{
383381
}
384382

385383
~ForInfoListT()
@@ -397,51 +395,42 @@ template< typename T, SizeT defaultLength> class ForInfoListT
397395
// must be called before access
398396
void InitSize( SizeT s)
399397
{
400-
// std::cerr<<this<<": InitSize("<<s<<")\n";
401398
assert( sz == 0);
402399
if( s == 0)
403400
return;
404-
sz = 0;
405-
if( s <= currentMaxLength) //initialise currentMaxLength objects
401+
sz = s;
402+
if( s < defaultLength)
406403
{
407-
for( SizeT i=0; i<currentMaxLength; ++i)
404+
for( SizeT i=0; i<s; ++i)
408405
eArr[ i].Init();
409406
return;
410407
}
411408
eArr = new T[ s]; // constructor called
412-
currentMaxLength=s;
413409
}
414410
// only needed for EXECUTE
415411
void resize( SizeT s)
416412
{
417-
// std::cerr<<this<<": resize("<<s<<"): ";
418-
if( s == sz) {
419-
// std::cerr<<" == "<<sz<<": return.\n";
413+
if( s == sz)
420414
return;
421-
}
422415
if( s < sz) // shrink
423416
{
424-
// std::cerr << " < " << sz << ": shrink.\n";
425417
for( SizeT i=s; i<sz; ++i)
426418
eArr[ i].ClearInit(); // in case eArr was allocated
427419
sz = s;
428420
return;
429421
}
430422
// s > sz -> grow
431-
if( s <= currentMaxLength && eArr == reinterpret_cast<T*>(buf))
423+
if( s <= defaultLength && eArr == reinterpret_cast<T*>(buf))
432424
{
433-
// std::cerr << " > " << sz << " but <= currentMaxLength : grow.\n";
434425
for( SizeT i=sz; i<s; ++i)
435426
eArr[ i].Init();
436427
sz = s;
437428
return;
438429
}
439430
// this should never happen (or only in extreme rarely cases)
440431
// the performance will go down
441-
// s > currentMaxLength
442-
// std::cerr << " > " << sz << " and > currentMaxLength : should not happen.\n";
432+
// s > defaultLength
443433
T* newArr = new T[ s]; // ctor called
444-
currentMaxLength=s;
445434
if( eArr != reinterpret_cast<T*>(buf))
446435
{
447436
for( SizeT i=0; i<sz; ++i)
@@ -462,7 +451,7 @@ template< typename T, SizeT defaultLength> class ForInfoListT
462451
sz = s;
463452
}
464453
// T operator[]( SizeT i) const { assert( i<sz); return eArr[i];}
465-
T& operator[]( SizeT i) { assert( i<currentMaxLength); return eArr[i];}
454+
T& operator[]( SizeT i) { assert( i<sz); return eArr[i];}
466455
SizeT size() const { return sz;}
467456
iterator begin() const { return &eArr[0];}
468457
iterator end() const { return &eArr[sz];}
@@ -474,6 +463,7 @@ template< typename T, SizeT defaultLength> class ForInfoListT
474463
};
475464

476465

466+
477467
// for UD subroutines (written in GDL) ********************************
478468
class EnvUDT: public EnvBaseT
479469
{
@@ -491,7 +481,8 @@ class EnvUDT: public EnvBaseT
491481
};
492482

493483
private:
494-
ForInfoListT<ForLoopInfoT, MAX_LOOPS_NUMBER> forLoopInfo; //defaults to $MAIN$ values in dpro.hpp
484+
ForInfoListT<ForLoopInfoT, 32> forLoopInfo;
485+
// std::vector<ForLoopInfoT> forLoopInfo;
495486

496487
ProgNodeP ioError;
497488
DLong onError; // on_error setting

0 commit comments

Comments
 (0)