@@ -785,29 +785,22 @@ void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
785
785
E->setRParenLoc (readSourceLocation ());
786
786
}
787
787
788
- static StringRef saveStrToCtx (const std::string &S, ASTContext &Ctx) {
789
- char *Buf = new (Ctx) char [S.size ()];
790
- std::copy (S.begin (), S.end (), Buf);
791
- return StringRef (Buf, S.size ());
792
- }
793
-
794
788
static ConstraintSatisfaction
795
789
readConstraintSatisfaction (ASTRecordReader &Record) {
796
790
ConstraintSatisfaction Satisfaction;
797
791
Satisfaction.IsSatisfied = Record.readInt ();
798
792
Satisfaction.ContainsErrors = Record.readInt ();
793
+ const ASTContext &C = Record.getContext ();
799
794
if (!Satisfaction.IsSatisfied ) {
800
795
unsigned NumDetailRecords = Record.readInt ();
801
796
for (unsigned i = 0 ; i != NumDetailRecords; ++i) {
802
797
if (/* IsDiagnostic */ Record.readInt ()) {
803
798
SourceLocation DiagLocation = Record.readSourceLocation ();
804
- StringRef DiagMessage =
805
- saveStrToCtx (Record.readString (), Record.getContext ());
799
+ StringRef DiagMessage = C.backupStr (Record.readString ());
806
800
807
801
Satisfaction.Details .emplace_back (
808
- new (Record.getContext ())
809
- ConstraintSatisfaction::SubstitutionDiagnostic (DiagLocation,
810
- DiagMessage));
802
+ new (C) ConstraintSatisfaction::SubstitutionDiagnostic (
803
+ DiagLocation, DiagMessage));
811
804
} else
812
805
Satisfaction.Details .emplace_back (Record.readExpr ());
813
806
}
@@ -828,12 +821,10 @@ void ASTStmtReader::VisitConceptSpecializationExpr(
828
821
829
822
static concepts::Requirement::SubstitutionDiagnostic *
830
823
readSubstitutionDiagnostic (ASTRecordReader &Record) {
831
- StringRef SubstitutedEntity =
832
- saveStrToCtx (Record.readString (), Record.getContext ());
833
-
824
+ const ASTContext &C = Record.getContext ();
825
+ StringRef SubstitutedEntity = C.backupStr (Record.readString ());
834
826
SourceLocation DiagLoc = Record.readSourceLocation ();
835
- StringRef DiagMessage =
836
- saveStrToCtx (Record.readString (), Record.getContext ());
827
+ StringRef DiagMessage = C.backupStr (Record.readString ());
837
828
838
829
return new (Record.getContext ())
839
830
concepts::Requirement::SubstitutionDiagnostic{SubstitutedEntity, DiagLoc,
@@ -919,22 +910,21 @@ void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {
919
910
std::move (*Req));
920
911
} break ;
921
912
case concepts::Requirement::RK_Nested: {
913
+ ASTContext &C = Record.getContext ();
922
914
bool HasInvalidConstraint = Record.readInt ();
923
915
if (HasInvalidConstraint) {
924
- StringRef InvalidConstraint =
925
- saveStrToCtx (Record.readString (), Record.getContext ());
926
- R = new (Record.getContext ()) concepts::NestedRequirement (
916
+ StringRef InvalidConstraint = C.backupStr (Record.readString ());
917
+ R = new (C) concepts::NestedRequirement (
927
918
Record.getContext (), InvalidConstraint,
928
919
readConstraintSatisfaction (Record));
929
920
break ;
930
921
}
931
922
Expr *E = Record.readExpr ();
932
923
if (E->isInstantiationDependent ())
933
- R = new (Record. getContext () ) concepts::NestedRequirement (E);
924
+ R = new (C ) concepts::NestedRequirement (E);
934
925
else
935
- R = new (Record.getContext ())
936
- concepts::NestedRequirement (Record.getContext (), E,
937
- readConstraintSatisfaction (Record));
926
+ R = new (C) concepts::NestedRequirement (
927
+ C, E, readConstraintSatisfaction (Record));
938
928
} break ;
939
929
}
940
930
if (!R)
0 commit comments