diff --git a/src/sed/compiler.rs b/src/sed/compiler.rs index 01c3a6d..dd6878a 100644 --- a/src/sed/compiler.rs +++ b/src/sed/compiler.rs @@ -120,7 +120,7 @@ fn patch_block_endings(head: Option>>) { } // 3) splice the tail’s `.next` to splice_target - tail.borrow_mut().next = splice_target.clone(); + tail.borrow_mut().next.clone_from(&splice_target); } // drop the borrow before moving on @@ -140,7 +140,7 @@ fn populate_label_map( mut cur: Option>>, context: &mut ProcessingContext, ) -> UResult<()> { - while let Some(rc_cmd) = cur { + while let Some(rc_cmd) = cur.take() { // Borrow mutably just long enough to inspect/rewire this node let cmd = rc_cmd.borrow_mut(); @@ -163,14 +163,14 @@ fn populate_label_map( context.label_to_command_map.insert(label, rc_cmd.clone()); } - cur = cmd.next.clone(); + cur.clone_from(&cmd.next); } Ok(()) } /// Populate the context's address range command list with references to associated commands. fn populate_range_commands(mut cur: Option>>, context: &mut ProcessingContext) { - while let Some(rc_cmd) = cur { + while let Some(rc_cmd) = cur.take() { // Borrow mutably just long enough to inspect/rewire this node let cmd = rc_cmd.borrow_mut(); @@ -184,7 +184,7 @@ fn populate_range_commands(mut cur: Option>>, context: &mut context.range_commands.push(Rc::clone(&rc_cmd)); } - cur = cmd.next.clone(); + cur.clone_from(&cmd.next); } } @@ -194,7 +194,7 @@ fn resolve_branch_targets( mut cur: Option>>, context: &mut ProcessingContext, ) -> UResult<()> { - while let Some(rc_cmd) = cur { + while let Some(rc_cmd) = cur.take() { // Borrow mutably just long enough to inspect/rewire this node let mut cmd = rc_cmd.borrow_mut(); @@ -233,7 +233,7 @@ fn resolve_branch_targets( } // Advance to the next sibling - cur = cmd.next.clone(); + cur.clone_from(&cmd.next); } Ok(()) } diff --git a/src/sed/processor.rs b/src/sed/processor.rs index 9dde89f..77de06b 100644 --- a/src/sed/processor.rs +++ b/src/sed/processor.rs @@ -444,12 +444,12 @@ fn process_file( }; // Loop over script commands. - while let Some(command_rc) = current { + while let Some(command_rc) = current.take() { let mut command = command_rc.borrow_mut(); if !applies(&mut command, reader, &mut pattern, context)? { // Advance to next command - current = command.next.clone(); + current.clone_from(&command.next); continue; } @@ -457,7 +457,7 @@ fn process_file( '{' => { // Block begin; start processing the enclosed ones. let body = extract_variant!(command, BranchTarget); - current = body.clone(); + current.clone_from(body); continue; } '}' => { @@ -475,7 +475,7 @@ fn process_file( let target = extract_variant!(command, BranchTarget); if target.is_some() { // New command to execute - current = target.clone(); + current.clone_from(target); continue; } else { // Branch to the end of the script. @@ -502,7 +502,7 @@ fn process_file( if let Some(pos) = pattern.as_str()?.find('\n') { let (s, _) = pattern.fields_mut()?; s.drain(..=pos); - current = commands.clone(); + current.clone_from(&commands); continue; } else { // Same as d @@ -598,7 +598,7 @@ fn process_file( context.substitution_made = false; if target.is_some() { // New command to execute - current = target.clone(); + current.clone_from(target); continue; } else { // Branch to the end of the script. @@ -635,7 +635,7 @@ fn process_file( _ => panic!("invalid command code"), } // match // Advance to next command. - current = command.next.clone(); + current.clone_from(&command.next); } if !context.quiet {