@@ -557,8 +557,9 @@ class SinglePayloadEnumTypeInfo: public EnumTypeInfo {
557
557
//
558
558
// The above logic generalizes the following important cases:
559
559
// * A payload with XIs will generally have enough to
560
- // encode all payloadcases. It will have no discriminator
561
- // case, so everything is effectively on "page zero."
560
+ // encode all payload cases. If so, then it will have
561
+ // no discriminator allocated, so the discriminator is
562
+ // always treated as zero.
562
563
// * If the payload has no XIs but is not zero-sized, then
563
564
// we'll need a page one. That page will usually be
564
565
// large enough to encode all non-payload cases.
@@ -586,13 +587,14 @@ class SinglePayloadEnumTypeInfo: public EnumTypeInfo {
586
587
unsigned nonPayloadCasesUsingXIs = PayloadCase.TI .getNumExtraInhabitants ();
587
588
int ComputedCase = 0 ;
588
589
if (discriminator == 0 ) {
589
- // Discriminator is for a page that encodes payload ( and maybe tag data too)
590
+ // This is Page 0, which encodes payload case and some additional cases in Xis
590
591
int XITag;
591
592
if (!PayloadCase.TI .readExtraInhabitantIndex (reader, address, &XITag)) {
592
593
return false ;
593
594
}
594
595
ComputedCase = XITag < 0 ? 0 : XITag + 1 ;
595
596
} else {
597
+ // This is some other page, so the entire payload area is just a case index
596
598
unsigned payloadTag;
597
599
if (!reader.readInteger (address, PayloadSize, &payloadTag)) {
598
600
return false ;
@@ -602,10 +604,9 @@ class SinglePayloadEnumTypeInfo: public EnumTypeInfo {
602
604
? ValueWitnessFlags::MaxNumExtraInhabitants
603
605
: (1UL << (PayloadSize * 8UL ));
604
606
ComputedCase =
605
- 1
606
- + nonPayloadCasesUsingXIs
607
- + (discriminator - 1 ) * casesPerNonPayloadPage
608
- + payloadTag;
607
+ 1 + nonPayloadCasesUsingXIs // Cases on page 0
608
+ + (discriminator - 1 ) * casesPerNonPayloadPage // Cases on other pages
609
+ + payloadTag; // Cases on this page
609
610
}
610
611
if (static_cast <unsigned >(ComputedCase) < getNumCases ()) {
611
612
*CaseIndex = ComputedCase;
0 commit comments