&str::to_string -> &str::to_owned for variables

This commit is contained in:
Jeong YunWon 2020-02-05 22:03:36 +09:00
parent 7860fc877d
commit 04c29f384e
2 changed files with 21 additions and 21 deletions

View file

@ -290,7 +290,7 @@ impl<O: OutputStream> Compiler<O> {
fn load_name(&mut self, name: &str) {
let scope = self.scope_for_name(name);
self.emit(Instruction::LoadName {
name: name.to_string(),
name: name.to_owned(),
scope,
});
}
@ -298,7 +298,7 @@ impl<O: OutputStream> Compiler<O> {
fn store_name(&mut self, name: &str) {
let scope = self.scope_for_name(name);
self.emit(Instruction::StoreName {
name: name.to_string(),
name: name.to_owned(),
scope,
});
}
@ -359,7 +359,7 @@ impl<O: OutputStream> Compiler<O> {
for name in names {
// import symbol from module:
self.emit(Instruction::ImportFrom {
name: name.symbol.to_string(),
name: name.symbol.to_owned(),
});
// Store module under proper name:
@ -619,13 +619,13 @@ impl<O: OutputStream> Compiler<O> {
match &expression.node {
ast::ExpressionType::Identifier { name } => {
self.emit(Instruction::DeleteName {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::DeleteAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::Subscript { a, b } => {
@ -701,7 +701,7 @@ impl<O: OutputStream> Compiler<O> {
compile_varargs(&args.kwarg),
self.source_path.clone().unwrap(),
line_number,
name.to_string(),
name.to_owned(),
));
self.enter_scope();
@ -909,7 +909,7 @@ impl<O: OutputStream> Compiler<O> {
if let Some(annotation) = &arg.annotation {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: arg.arg.to_string(),
value: arg.arg.to_owned(),
},
});
self.compile_expression(&annotation)?;
@ -982,7 +982,7 @@ impl<O: OutputStream> Compiler<O> {
Varargs::None,
self.source_path.clone().unwrap(),
line_number,
name.to_string(),
name.to_owned(),
));
self.enter_scope();
@ -1022,7 +1022,7 @@ impl<O: OutputStream> Compiler<O> {
});
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});
@ -1044,7 +1044,7 @@ impl<O: OutputStream> Compiler<O> {
for keyword in keywords {
if let Some(name) = &keyword.name {
kwarg_names.push(bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
});
} else {
// This means **kwargs!
@ -1308,7 +1308,7 @@ impl<O: OutputStream> Compiler<O> {
});
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});
self.emit(Instruction::StoreSubscript);
@ -1332,7 +1332,7 @@ impl<O: OutputStream> Compiler<O> {
ast::ExpressionType::Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::StoreAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
ast::ExpressionType::List { elements } | ast::ExpressionType::Tuple { elements } => {
@ -1605,7 +1605,7 @@ impl<O: OutputStream> Compiler<O> {
Attribute { value, name } => {
self.compile_expression(value)?;
self.emit(Instruction::LoadAttr {
name: name.to_string(),
name: name.to_owned(),
});
}
Compare { vals, ops } => {
@ -1795,7 +1795,7 @@ impl<O: OutputStream> Compiler<O> {
if let Some(name) = &keyword.name {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
},
});
self.compile_expression(&keyword.value)?;
@ -1858,7 +1858,7 @@ impl<O: OutputStream> Compiler<O> {
for keyword in keywords {
if let Some(name) = &keyword.name {
kwarg_names.push(bytecode::Constant::String {
value: name.to_string(),
value: name.to_owned(),
});
} else {
// This means **kwargs!
@ -1927,7 +1927,7 @@ impl<O: OutputStream> Compiler<O> {
ast::ComprehensionKind::Set { .. } => "<setcomp>",
ast::ComprehensionKind::Dict { .. } => "<dictcomp>",
}
.to_string();
.to_owned();
let line_number = self.get_source_line_number();
// Create magnificent function <listcomp>:
@ -2099,7 +2099,7 @@ impl<O: OutputStream> Compiler<O> {
ast::StringGroup::Constant { value } => {
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: value.to_string(),
value: value.to_owned(),
},
});
}
@ -2266,7 +2266,7 @@ mod tests {
let mut compiler: Compiler = Default::default();
compiler.source_path = Some("source_path".to_owned());
compiler.push_new_code_object("<module>".to_owned());
let ast = parser::parse_program(&source.to_string()).unwrap();
let ast = parser::parse_program(source).unwrap();
let symbol_scope = make_symbol_table(&ast).unwrap();
compiler.compile_program(&ast, symbol_scope).unwrap();
compiler.pop_code_object()

View file

@ -105,7 +105,7 @@ pub struct Symbol {
impl Symbol {
fn new(name: &str) -> Self {
Symbol {
name: name.to_string(),
name: name.to_owned(),
// table,
scope: SymbolScope::Unknown,
is_param: false,
@ -304,7 +304,7 @@ impl SymbolTableBuilder {
}
fn enter_scope(&mut self, name: &str, typ: SymbolTableType, line_number: usize) {
let table = SymbolTable::new(name.to_string(), typ, line_number);
let table = SymbolTable::new(name.to_owned(), typ, line_number);
self.tables.push(table);
}
@ -793,7 +793,7 @@ impl SymbolTableBuilder {
// Insert symbol when required:
if !containing {
let symbol = Symbol::new(name);
table.symbols.insert(name.to_string(), symbol);
table.symbols.insert(name.to_owned(), symbol);
}
// Set proper flags on symbol: