mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
Explicit as_str
(no deref), add no allocation methods (#8826)
## Summary This PR is a follow-up to the AST refactor which does the following: - Remove `Deref` implementation on `StringLiteralValue` and use explicit `as_str` calls instead. The `Deref` implementation would implicitly perform allocations in case of implicitly concatenated strings. This is to make sure the allocation is explicit. - Now, certain methods can be implemented to do zero allocations which have been implemented in this PR. They are: - `is_empty` - `len` - `chars` - Custom `PartialEq` implementation to compare each character ## Test Plan Run the linter test suite and make sure all tests pass.
This commit is contained in:
parent
017e829115
commit
626b0577cd
28 changed files with 95 additions and 77 deletions
|
@ -24,7 +24,7 @@ where
|
|||
fn add_to_names<'a>(elts: &'a [Expr], names: &mut Vec<&'a str>, flags: &mut DunderAllFlags) {
|
||||
for elt in elts {
|
||||
if let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = elt {
|
||||
names.push(value);
|
||||
names.push(value.as_str());
|
||||
} else {
|
||||
*flags |= DunderAllFlags::INVALID_OBJECT;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue