mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:01:07 +01:00
Change StringLiteral to less frequently allocate a new string. (#3314)
Building on #3311, which started moving the result string into a `unique_ptr`, instead have `StringLiteral` use a `BumpPtrAllocator` to manage memory. But also, detect when a string is really trivial during `Lex` and, if so, return `contents_` directly.
This commit is contained in:
@@ -25,13 +25,14 @@ class StringLiteralTest : public ::testing::Test {
|
||||
return *result;
|
||||
}
|
||||
|
||||
auto Parse(llvm::StringRef text) -> std::string {
|
||||
auto Parse(llvm::StringRef text) -> llvm::StringRef {
|
||||
StringLiteral token = Lex(text);
|
||||
Testing::SingleTokenDiagnosticTranslator translator(text);
|
||||
DiagnosticEmitter<const char*> emitter(translator, error_tracker);
|
||||
return token.ComputeValue(emitter);
|
||||
return token.ComputeValue(allocator, emitter);
|
||||
}
|
||||
|
||||
llvm::BumpPtrAllocator allocator;
|
||||
ErrorTrackingDiagnosticConsumer error_tracker;
|
||||
};
|
||||
|
||||
@@ -311,7 +312,7 @@ TEST_F(StringLiteralTest, StringLiteralBadEscapeSequence) {
|
||||
|
||||
for (llvm::StringLiteral test : testcases) {
|
||||
error_tracker.Reset();
|
||||
auto value = Parse(test);
|
||||
Parse(test);
|
||||
EXPECT_TRUE(error_tracker.seen_error()) << "`" << test << "`";
|
||||
// TODO: Test value produced by error recovery.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user