mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[libSyntax] Add a reference counted version of OwnedString
We cannot use unowned strings for token texts of incrementally parsed syntax trees since the source buffer to which reused nodes refer will have been freed for reused nodes. Always copying the token text whenever OwnedString is passed is too expensive. A reference counted copy of the string allows us to keep the token's string alive across incremental parses while eliminating unnecessary copies.
This commit is contained in:
@@ -162,9 +162,9 @@ template <> struct MappingTraits<swift::RC<swift::RawSyntax>> {
|
||||
StringRef nodeIdString;
|
||||
in.mapRequired("id", nodeIdString);
|
||||
unsigned nodeId = std::atoi(nodeIdString.data());
|
||||
value =
|
||||
swift::RawSyntax::make(tokenKind, text, leadingTrivia, trailingTrivia,
|
||||
presence, /*Arena=*/nullptr, nodeId);
|
||||
value = swift::RawSyntax::make(
|
||||
tokenKind, swift::OwnedString::makeRefCounted(text), leadingTrivia,
|
||||
trailingTrivia, presence, /*Arena=*/nullptr, nodeId);
|
||||
} else {
|
||||
swift::SyntaxKind kind;
|
||||
in.mapRequired("kind", kind);
|
||||
|
||||
Reference in New Issue
Block a user