From 969f9d47338fc36ebb6d24ad3a51e45eda07fd58 Mon Sep 17 00:00:00 2001
From: Eli Friedman <eli.friedman@gmail.com>
Date: Tue, 10 May 2011 17:11:21 +0000
Subject: [PATCH] Don't strlen() every file before parsing it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131132 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Lex/Lexer.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 16cc4f8fd54..3b1149c08af 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -76,7 +76,8 @@ void Lexer::InitLexer(const char *BufStart, const char *BufPtr,
   // skip the UTF-8 BOM if it's present.
   if (BufferStart == BufferPtr) {
     // Determine the size of the BOM.
-    size_t BOMLength = llvm::StringSwitch<size_t>(BufferStart)
+    llvm::StringRef Buf(BufferStart, BufferEnd - BufferStart);
+    size_t BOMLength = llvm::StringSwitch<size_t>(Buf)
       .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
       .Default(0);
 
-- 
GitLab