Skip to content

Commit 1789f85

Browse files
authored
Simplify
1 parent abd6ebf commit 1789f85

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

llvm/lib/ProfileData/SampleProf.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/Support/ErrorHandling.h"
2323
#include "llvm/Support/LEB128.h"
2424
#include "llvm/Support/raw_ostream.h"
25+
#include <algorithm>
2526
#include <string>
2627
#include <system_error>
2728

@@ -398,28 +399,19 @@ LLVM_DUMP_METHOD void FunctionSamples::dump() const { print(dbgs(), 0); }
398399

399400
std::error_code ProfileSymbolList::read(const uint8_t *Data,
400401
uint64_t ListSize) {
401-
const char *ListStart = reinterpret_cast<const char *>(Data);
402-
uint64_t Size = 0;
403-
uint64_t StrNum = 0;
404-
uint64_t ExpectedCount = 0;
405-
406402
// Scan forward to see how many elements we expect.
407-
while (Size < ListSize) {
408-
if (ListStart[Size] == '\0') ExpectedCount++;
409-
Size++;
410-
}
411-
403+
uint64_t ExpectedCount = std::count(Data, Data + ListSize, 0);
412404
reserve(ExpectedCount);
413405

414-
Size = 0;
415-
406+
const char *ListStart = reinterpret_cast<const char *>(Data);
407+
uint64_t Size = 0;
408+
uint64_t StrNum = 0;
416409
while (Size < ListSize && StrNum < ProfileSymbolListCutOff) {
417410
StringRef Str(ListStart + Size);
418411
add(Str);
419412
Size += Str.size() + 1;
420413
StrNum++;
421414
}
422-
423415
if (Size != ListSize && StrNum != ProfileSymbolListCutOff)
424416
return sampleprof_error::malformed;
425417
return sampleprof_error::success;

0 commit comments

Comments
 (0)