@@ -81,7 +81,7 @@ template <typename DSV = parser::DataStmtValue> class ValueListIterator {
81
81
};
82
82
83
83
template <typename DSV> void ValueListIterator<DSV>::SetRepetitionCount() {
84
- for (repetitionsRemaining_ = 1 ; at_ != end_; ++at_) {
84
+ for (; at_ != end_; ++at_) {
85
85
auto repetitions{GetValue ().repetitions };
86
86
if (repetitions < 0 ) {
87
87
hasFatalError_ = true ;
@@ -335,10 +335,15 @@ bool DataInitializationCompiler<DSV>::InitElement(
335
335
}
336
336
}};
337
337
const auto GetImage{[&]() -> evaluate::InitialImage & {
338
- auto iter{inits_.emplace (&symbol, symbol.size ())};
339
- auto &symbolInit{iter.first ->second };
340
- symbolInit.initializedRanges .emplace_back (
341
- offsetSymbol.offset (), offsetSymbol.size ());
338
+ // This could be (and was) written to always call std::map<>::emplace(),
339
+ // which should handle duplicate entries gracefully, but it was still
340
+ // causing memory allocation & deallocation with gcc.
341
+ auto iter{inits_.find (&symbol)};
342
+ if (iter == inits_.end ()) {
343
+ iter = inits_.emplace (&symbol, symbol.size ()).first ;
344
+ }
345
+ auto &symbolInit{iter->second };
346
+ symbolInit.NoteInitializedRange (offsetSymbol);
342
347
return symbolInit.image ;
343
348
}};
344
349
const auto OutOfRangeError{[&]() {
@@ -590,17 +595,15 @@ static void PopulateWithComponentDefaults(SymbolDataInitialization &init,
590
595
}
591
596
}
592
597
if (initialized) {
593
- init.initializedRanges .emplace_back (
594
- componentOffset, component.size ());
598
+ init.NoteInitializedRange (componentOffset, component.size ());
595
599
}
596
600
}
597
601
} else if (const auto *proc{component.detailsIf <ProcEntityDetails>()}) {
598
602
if (proc->init () && *proc->init ()) {
599
603
SomeExpr procPtrInit{evaluate::ProcedureDesignator{**proc->init ()}};
600
604
auto extant{init.image .AsConstantPointer (componentOffset)};
601
605
if (!extant || !(*extant == procPtrInit)) {
602
- init.initializedRanges .emplace_back (
603
- componentOffset, component.size ());
606
+ init.NoteInitializedRange (componentOffset, component.size ());
604
607
init.image .AddPointer (componentOffset, std::move (procPtrInit));
605
608
}
606
609
}
@@ -651,7 +654,7 @@ static void IncorporateExplicitInitialization(
651
654
if (iter != inits.end ()) { // DATA statement initialization
652
655
for (const auto &range : iter->second .initializedRanges ) {
653
656
auto at{offset + range.start ()};
654
- combined.initializedRanges . emplace_back (at, range.size ());
657
+ combined.NoteInitializedRange (at, range.size ());
655
658
combined.image .Incorporate (
656
659
at, iter->second .image , range.start (), range.size ());
657
660
}
@@ -663,15 +666,15 @@ static void IncorporateExplicitInitialization(
663
666
if (IsPointer (mutableSymbol)) {
664
667
if (auto *object{mutableSymbol.detailsIf <ObjectEntityDetails>()}) {
665
668
if (object->init ()) {
666
- combined.initializedRanges . emplace_back (offset, mutableSymbol.size ());
669
+ combined.NoteInitializedRange (offset, mutableSymbol.size ());
667
670
combined.image .AddPointer (offset, *object->init ());
668
671
if (removeOriginalInits) {
669
672
object->init ().reset ();
670
673
}
671
674
}
672
675
} else if (auto *proc{mutableSymbol.detailsIf <ProcEntityDetails>()}) {
673
676
if (proc->init () && *proc->init ()) {
674
- combined.initializedRanges . emplace_back (offset, mutableSymbol.size ());
677
+ combined.NoteInitializedRange (offset, mutableSymbol.size ());
675
678
combined.image .AddPointer (
676
679
offset, SomeExpr{evaluate::ProcedureDesignator{**proc->init ()}});
677
680
if (removeOriginalInits) {
@@ -681,7 +684,7 @@ static void IncorporateExplicitInitialization(
681
684
}
682
685
} else if (auto *object{mutableSymbol.detailsIf <ObjectEntityDetails>()}) {
683
686
if (!IsNamedConstant (mutableSymbol) && object->init ()) {
684
- combined.initializedRanges . emplace_back (offset, mutableSymbol.size ());
687
+ combined.NoteInitializedRange (offset, mutableSymbol.size ());
685
688
combined.image .Add (
686
689
offset, mutableSymbol.size (), *object->init (), foldingContext);
687
690
if (removeOriginalInits) {
0 commit comments