Skip to content

Commit 252e670

Browse files
committed
chore: Fix clippy issues
1 parent 795edda commit 252e670

File tree

3 files changed

+16
-38
lines changed

3 files changed

+16
-38
lines changed

src/analyzer.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ impl StackStatus {
2626
&& self.deepest_altstack_accessed == 0
2727
&& self.deepest_stack_accessed == 0
2828
}
29-
29+
3030
pub fn is_valid_final_state_with_inputs(&self) -> bool {
31-
self.stack_changed == 1
32-
&& self.altstack_changed == 0
33-
&& self.deepest_altstack_accessed == 0
31+
self.stack_changed == 1 && self.altstack_changed == 0 && self.deepest_altstack_accessed == 0
3432
}
3533
}
3634

@@ -321,18 +319,11 @@ impl StackAnalyzer {
321319
}
322320

323321
fn stack_change(&mut self, stack_status: StackStatus) {
324-
let status;
325-
match self.if_stack.last_mut() {
326-
None => {
327-
status = self.stack_status.borrow_mut();
328-
}
329-
Some(IfStackEle::IfFlow(stack_status)) => {
330-
status = stack_status.borrow_mut();
331-
}
332-
Some(IfStackEle::ElseFlow((_, stack_status))) => {
333-
status = stack_status.borrow_mut();
334-
}
335-
}
322+
let status = match self.if_stack.last_mut() {
323+
None => self.stack_status.borrow_mut(),
324+
Some(IfStackEle::IfFlow(stack_status)) => stack_status.borrow_mut(),
325+
Some(IfStackEle::ElseFlow((_, stack_status))) => stack_status.borrow_mut(),
326+
};
336327
let i = status.deepest_stack_accessed.borrow_mut();
337328
let j = status.stack_changed.borrow_mut();
338329
let x = status.deepest_altstack_accessed.borrow_mut();

src/builder.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ impl StructuredScript {
150150

151151
fn get_script_block(&mut self) -> &mut ScriptBuf {
152152
// Check if the last block is a Script block
153-
let is_script_block = match self.blocks.last_mut() {
154-
Some(Block::Script(_)) => true,
155-
_ => false,
156-
};
153+
let is_script_block = matches!(self.blocks.last_mut(), Some(Block::Script(_)));
157154

158155
// Create a new Script block if necessary
159156
if !is_script_block {
@@ -385,23 +382,20 @@ impl StructuredScript {
385382
(chunk_sizes, scripts)
386383
}
387384

388-
pub fn analyze_stack(mut self) -> StackStatus {
385+
pub fn analyze_stack(self) -> StackStatus {
389386
match self.stack_hint {
390387
Some(hint) => hint,
391388
None => {
392389
let mut analyzer = StackAnalyzer::new();
393-
analyzer.analyze_status(&mut self)
390+
analyzer.analyze_status(&self)
394391
}
395392
}
396393
}
397394

398395
pub fn get_stack(&self, analyzer: &mut StackAnalyzer) -> StackStatus {
399396
match &self.stack_hint {
400397
Some(x) => x.clone(),
401-
None => {
402-
403-
analyzer.analyze_status(self)
404-
}
398+
None => analyzer.analyze_status(self),
405399
}
406400
}
407401

src/chunker.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ impl Chunk {
129129
}
130130

131131
pub fn total_stack_size(&self) -> usize {
132-
(self.stats.stack_output_size)
133-
.try_into()
134-
.expect("Chunk stack size negative at the end. This is a bug.")
132+
self.stats.stack_output_size
135133
}
136134
}
137135

@@ -241,12 +239,7 @@ impl Chunker {
241239
let max_depth = 8;
242240
let mut depth = 0;
243241

244-
loop {
245-
let builder = match self.call_stack.pop() {
246-
Some(builder) => *builder,
247-
None => break,
248-
};
249-
242+
while let Some(builder) = self.call_stack.pop() {
250243
assert!(
251244
undo_info.num_unclosed_ifs + builder.num_unclosed_ifs() >= 0,
252245
"More OP_ENDIF's than OP_IF's in the script. num_unclosed_if: {:?} at positions: {:?}",
@@ -259,7 +252,7 @@ impl Chunker {
259252
if chunk_len + block_len <= self.target_chunk_size {
260253
// Adding the current builder remains a valid solution regarding chunk size.
261254
chunk_len += block_len;
262-
undo_info.update(builder);
255+
undo_info.update(*builder);
263256
if undo_info.valid(self.stack_limit) {
264257
// We will keep all the structured scripts in undo_info in the chunk.
265258
chunk_scripts.extend(undo_info.reset());
@@ -276,7 +269,7 @@ impl Chunker {
276269

277270
// Don't split up script_bufs and scripts that have a (manually set) stack hint.
278271
if builder.is_script_buf() || builder.has_stack_hint() {
279-
self.call_stack.push(Box::new(builder));
272+
self.call_stack.push(builder);
280273
break;
281274
}
282275
let mut contains_call = false;
@@ -302,7 +295,7 @@ impl Chunker {
302295
);
303296
depth += 1;
304297
} else {
305-
self.call_stack.push(Box::new(builder));
298+
self.call_stack.push(builder);
306299
break;
307300
}
308301
}

0 commit comments

Comments
 (0)