Skip to content

Commit 4292086

Browse files
[ProfileData] Use ArrayRef in ProfOStream::patch (NFC) (#85317)
We always apply all of the items in PatchItems. This patch simplifies the interface of ProfOStream::patch by switching to ArrayRef.
1 parent 6b2bab2 commit 4292086

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ class ProfOStream {
6060
// \c patch can only be called when all data is written and flushed.
6161
// For raw_string_ostream, the patch is done on the target string
6262
// directly and it won't be reflected in the stream's internal buffer.
63-
void patch(PatchItem *P, int NItems) {
63+
void patch(ArrayRef<PatchItem> P) {
6464
using namespace support;
6565

6666
if (IsFDOStream) {
6767
raw_fd_ostream &FDOStream = static_cast<raw_fd_ostream &>(OS);
6868
const uint64_t LastPos = FDOStream.tell();
69-
for (int K = 0; K < NItems; K++) {
70-
FDOStream.seek(P[K].Pos);
71-
for (int I = 0; I < P[K].N; I++)
72-
write(P[K].D[I]);
69+
for (const auto &K : P) {
70+
FDOStream.seek(K.Pos);
71+
for (int I = 0; I < K.N; I++)
72+
write(K.D[I]);
7373
}
7474
// Reset the stream to the last position after patching so that users
7575
// don't accidentally overwrite data. This makes it consistent with
@@ -78,11 +78,11 @@ class ProfOStream {
7878
} else {
7979
raw_string_ostream &SOStream = static_cast<raw_string_ostream &>(OS);
8080
std::string &Data = SOStream.str(); // with flush
81-
for (int K = 0; K < NItems; K++) {
82-
for (int I = 0; I < P[K].N; I++) {
81+
for (const auto &K : P) {
82+
for (int I = 0; I < K.N; I++) {
8383
uint64_t Bytes =
84-
endian::byte_swap<uint64_t, llvm::endianness::little>(P[K].D[I]);
85-
Data.replace(P[K].Pos + I * sizeof(uint64_t), sizeof(uint64_t),
84+
endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[I]);
85+
Data.replace(K.Pos + I * sizeof(uint64_t), sizeof(uint64_t),
8686
(const char *)&Bytes, sizeof(uint64_t));
8787
}
8888
}
@@ -575,7 +575,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
575575
{MemProfSectionStart + sizeof(uint64_t), &FramePayloadOffset, 1},
576576
{MemProfSectionStart + 2 * sizeof(uint64_t), &FrameTableOffset, 1},
577577
};
578-
OS.patch(PatchItems, 3);
578+
OS.patch(PatchItems);
579579
}
580580

581581
// BinaryIdSection has two parts:
@@ -693,7 +693,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
693693
{CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()),
694694
(int)CSSummarySize}};
695695

696-
OS.patch(PatchItems, std::size(PatchItems));
696+
OS.patch(PatchItems);
697697
} else {
698698
// Now do the final patch:
699699
PatchItem PatchItems[] = {
@@ -713,7 +713,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
713713
{CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()),
714714
(int)CSSummarySize}};
715715

716-
OS.patch(PatchItems, std::size(PatchItems));
716+
OS.patch(PatchItems);
717717
}
718718

719719
for (const auto &I : FunctionData)

0 commit comments

Comments
 (0)