Skip to content

Commit 61a1903

Browse files
committed
[Markup] Improve performance of appendWithXMLEscaping()
1 parent 31e7873 commit 61a1903

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

include/swift/Markup/XMLUtils.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,35 @@ namespace markup {
2222
// FIXME: copied from Clang's
2323
// CommentASTToXMLConverter::appendToResultWithXMLEscaping
2424
static inline void appendWithXMLEscaping(raw_ostream &OS, StringRef S) {
25-
for (const char C : S) {
26-
switch (C) {
25+
auto Start = S.begin(), Cursor = Start, End = S.end();
26+
for (; Cursor != End; ++Cursor) {
27+
switch (*Cursor) {
2728
case '&':
29+
OS.write(Start, Cursor - Start);
2830
OS << "&amp;";
2931
break;
3032
case '<':
33+
OS.write(Start, Cursor - Start);
3134
OS << "&lt;";
3235
break;
3336
case '>':
37+
OS.write(Start, Cursor - Start);
3438
OS << "&gt;";
3539
break;
3640
case '"':
41+
OS.write(Start, Cursor - Start);
3742
OS << "&quot;";
3843
break;
3944
case '\'':
45+
OS.write(Start, Cursor - Start);
4046
OS << "&apos;";
4147
break;
4248
default:
43-
OS << C;
44-
break;
49+
continue;
4550
}
51+
Start = Cursor + 1;
4652
}
53+
OS.write(Start, Cursor - Start);
4754
}
4855

4956
// FIXME: copied from Clang's

0 commit comments

Comments
 (0)