summaryrefslogtreecommitdiffstats
path: root/src/parsers.cc
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-09-12 17:17:11 (GMT)
committerEvan Martin <martine@danga.com>2011-09-12 18:46:18 (GMT)
commitf1139aff5deddacd899be064fad9ed5a185e7444 (patch)
tree2d293defa9fd2d257cb25a20d7a66c110fd1f50b /src/parsers.cc
parent0c8e0f761f55e78bdaaad8a92f39a724e81474bf (diff)
downloadNinja-f1139aff5deddacd899be064fad9ed5a185e7444.zip
Ninja-f1139aff5deddacd899be064fad9ed5a185e7444.tar.gz
Ninja-f1139aff5deddacd899be064fad9ed5a185e7444.tar.bz2
use StringPiece for makefile deps
Because of this, MakefileParser now returns pointers into the source makefile string rather than allocating new strings. Despite needing to take the result and stuff it into a new string anyway to canonicalize it, this takes another 50ms or so off the null Chrome build, likely due to the vector used in MakefileParser changing to a type that doesn't use any allocations. (I also experimented with making the vector reserve an initial size but didn't see any performance impact.)
Diffstat (limited to 'src/parsers.cc')
-rw-r--r--src/parsers.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/parsers.cc b/src/parsers.cc
index 849a3e1..567be6b 100644
--- a/src/parsers.cc
+++ b/src/parsers.cc
@@ -148,15 +148,24 @@ bool Tokenizer::ExpectIdent(const char* expected, string* err) {
return true;
}
-bool Tokenizer::ReadIdent(string* out) {
+bool Tokenizer::ReadIdent(StringPiece* out) {
PeekToken();
if (token_.type_ != Token::IDENT)
return false;
- out->assign(token_.pos_, token_.end_ - token_.pos_);
+ out->str_ = token_.pos_;
+ out->len_ = token_.end_ - token_.pos_;
ConsumeToken();
return true;
}
+bool Tokenizer::ReadIdent(string* out) {
+ StringPiece token;
+ if (!ReadIdent(&token))
+ return false;
+ out->assign(token.str_, token.len_);
+ return true;
+}
+
// A note on backslashes in Makefiles, from reading the docs:
// Backslash-newline is the line continuation character.
// Backslash-# escapes a # (otherwise meaningful as a comment start).
@@ -276,7 +285,7 @@ bool MakefileParser::Parse(const string& input, string* err) {
if (!tokenizer_.ExpectToken(Token::COLON, err))
return false;
while (tokenizer_.PeekToken() == Token::IDENT) {
- string in;
+ StringPiece in;
tokenizer_.ReadIdent(&in);
ins_.push_back(in);
}