[cfe-commits] r158272 - /cfe/trunk/lib/Rewrite/InclusionRewriter.cpp
Benjamin Kramer
benny.kra at googlemail.com
Sat Jun 9 06:18:14 PDT 2012
Author: d0k
Date: Sat Jun 9 08:18:14 2012
New Revision: 158272
URL: http://llvm.org/viewvc/llvm-project?rev=158272&view=rev
Log:
Replace a char counting helper function with std::count.
No functionality change.
Modified:
cfe/trunk/lib/Rewrite/InclusionRewriter.cpp
Modified: cfe/trunk/lib/Rewrite/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/InclusionRewriter.cpp?rev=158272&r1=158271&r2=158272&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/InclusionRewriter.cpp Sat Jun 9 08:18:14 2012
@@ -174,16 +174,6 @@
return NULL;
}
-/// Count the raw \\n characters in the \p Len characters from \p Pos.
-inline unsigned CountNewLines(const char *Pos, int Len) {
- const char *End = Pos + Len;
- unsigned Lines = 0;
- --Pos;
- while ((Pos = static_cast<const char*>(memchr(Pos + 1, '\n', End - Pos - 1))))
- ++Lines;
- return Lines;
-}
-
/// Detect the likely line ending style of \p FromFile by examining the first
/// newline found within it.
static StringRef DetectEOL(const MemoryBuffer &FromFile) {
@@ -209,8 +199,8 @@
return;
OS.write(FromFile.getBufferStart() + WriteFrom, WriteTo - WriteFrom);
// count lines manually, it's faster than getPresumedLoc()
- Line += CountNewLines(FromFile.getBufferStart() + WriteFrom,
- WriteTo - WriteFrom);
+ Line += std::count(FromFile.getBufferStart() + WriteFrom,
+ FromFile.getBufferStart() + WriteTo, '\n');
if (EnsureNewline) {
char LastChar = FromFile.getBufferStart()[WriteTo - 1];
if (LastChar != '\n' && LastChar != '\r')
More information about the cfe-commits
mailing list