mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-18 22:10:28 +00: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:
1 parent
1d6298290f
commit
b2cfd5a8a8
7 files changed
+149
-76
No files matched your search
@@ -652,12 +652,8 @@ class [[clang::internal_linkage]] TokenizedBuffer::Lexer {
|
||||
}
|
||||
|
||||
if (literal->is_terminated()) {
|
||||
// TODO: Refactor to reduce copies.
|
||||
// https://github.com/carbon-language/carbon-lang/pull/3311#discussion_r1366048360
|
||||
buffer_.computed_strings_.push_back(
|
||||
std::make_unique<std::string>(literal->ComputeValue(emitter_)));
|
||||
auto string_id = buffer_.value_stores_->strings().Add(
|
||||
*buffer_.computed_strings_.back());
|
||||
literal->ComputeValue(buffer_.allocator_, emitter_));
|
||||
auto token = buffer_.AddToken({.kind = TokenKind::StringLiteral,
|
||||
.token_line = string_line,
|
||||
.column = string_column,
|
||||
|
||||
Reference in new issue
Block a user