@@ -385,13 +385,10 @@ void getContainerSizeFuncDecl(const Container& c, std::string& code) {
385
385
code += fmt.str ();
386
386
}
387
387
388
- void getContainerSizeFuncDef (const Container& c, std::string& code) {
389
- // TODO deduplicate containers in a better way (this isn't robust to vector
390
- // reallocs):
391
- // - implement hash for ContainerInfo
392
- // - use ref<ContainerInfo>
393
- static std::unordered_set<const ContainerInfo*> usedContainers{};
394
- if (!usedContainers.insert (&c.containerInfo_ ).second ) {
388
+ void getContainerSizeFuncDef (std::unordered_set<const ContainerInfo*>& used,
389
+ const Container& c,
390
+ std::string& code) {
391
+ if (!used.insert (&c.containerInfo_ ).second ) {
395
392
return ;
396
393
}
397
394
@@ -410,15 +407,17 @@ void addGetSizeFuncDecls(const TypeGraph& typeGraph, std::string& code) {
410
407
}
411
408
}
412
409
413
- void addGetSizeFuncDefs (const TypeGraph& typeGraph,
414
- SymbolService& symbols,
415
- bool polymorphicInheritance,
416
- std::string& code) {
410
+ void addGetSizeFuncDefs (
411
+ const TypeGraph& typeGraph,
412
+ SymbolService& symbols,
413
+ std::unordered_set<const ContainerInfo*>& definedContainers,
414
+ bool polymorphicInheritance,
415
+ std::string& code) {
417
416
for (const Type& t : typeGraph.finalTypes ) {
418
417
if (const auto * c = dynamic_cast <const Class*>(&t)) {
419
418
getClassSizeFuncDef (*c, symbols, polymorphicInheritance, code);
420
419
} else if (const auto * con = dynamic_cast <const Container*>(&t)) {
421
- getContainerSizeFuncDef (*con, code);
420
+ getContainerSizeFuncDef (definedContainers, *con, code);
422
421
}
423
422
}
424
423
}
@@ -525,9 +524,10 @@ class TypeHandler<DB, %1%> {
525
524
.str ();
526
525
}
527
526
528
- void getContainerTypeHandler (const Container& c, std::string& code) {
529
- static std::unordered_set<const ContainerInfo*> usedContainers{};
530
- if (!usedContainers.insert (&c.containerInfo_ ).second ) {
527
+ void getContainerTypeHandler (std::unordered_set<const ContainerInfo*>& used,
528
+ const Container& c,
529
+ std::string& code) {
530
+ if (!used.insert (&c.containerInfo_ ).second ) {
531
531
return ;
532
532
}
533
533
@@ -543,12 +543,15 @@ void getContainerTypeHandler(const Container& c, std::string& code) {
543
543
code += fmt.str ();
544
544
}
545
545
546
- void addTypeHandlers (const TypeGraph& typeGraph, std::string& code) {
546
+ void addTypeHandlers (
547
+ std::unordered_set<const ContainerInfo*>& definedContainers,
548
+ const TypeGraph& typeGraph,
549
+ std::string& code) {
547
550
for (const Type& t : typeGraph.finalTypes ) {
548
551
if (const auto * c = dynamic_cast <const Class*>(&t)) {
549
552
getClassTypeHandler (*c, code);
550
553
} else if (const auto * con = dynamic_cast <const Container*>(&t)) {
551
- getContainerTypeHandler (*con, code);
554
+ getContainerTypeHandler (definedContainers, *con, code);
552
555
}
553
556
}
554
557
}
@@ -664,13 +667,13 @@ void CodeGen::generate(
664
667
665
668
if (config_.features [Feature::TypedDataSegment]) {
666
669
addStandardTypeHandlers (code);
667
- addTypeHandlers (typeGraph, code);
670
+ addTypeHandlers (definedContainers_, typeGraph, code);
668
671
} else {
669
672
addStandardGetSizeFuncDecls (code);
670
673
addGetSizeFuncDecls (typeGraph, code);
671
674
672
675
addStandardGetSizeFuncDefs (code);
673
- addGetSizeFuncDefs (typeGraph, symbols_,
676
+ addGetSizeFuncDefs (typeGraph, symbols_, definedContainers_,
674
677
config_.features [Feature::PolymorphicInheritance], code);
675
678
}
676
679
0 commit comments