Skip to content

Commit 64fbac8

Browse files
committed
Add depth
1 parent bbef1ff commit 64fbac8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/chunker.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ impl Chunker {
107107
let mut call_stack_undo = vec![];
108108
let mut chunk_len_undo = 0;
109109
let mut num_unclosed_ifs_undo = 0;
110+
111+
let max_depth = 3;
112+
let mut depth = 0;
110113

111114
loop {
112115
let builder = match self.call_stack.pop() {
@@ -148,10 +151,11 @@ impl Chunker {
148151
chunk_len_undo += block_len;
149152
num_unclosed_ifs_undo += script_unclosed_ifs;
150153
}
154+
depth = 0;
151155
num_unclosed_ifs += script_unclosed_ifs;
152156
chunk_len += block_len;
153157
} else if chunk_len + block_len > self.target_chunk_size
154-
&& (chunk_len < self.target_chunk_size - self.tolerance || chunk_len == 0)
158+
&& (chunk_len < self.target_chunk_size - self.tolerance || chunk_len == 0 || depth <= max_depth)
155159
{
156160
//println!("[INFO] Chunking a call now.");
157161
// Case 3: Current builder too large and there is no acceptable solution yet
@@ -177,14 +181,16 @@ impl Chunker {
177181
}
178182
}
179183
}
180-
assert!(contains_call, "No support for chunking up ScriptBufs");
184+
assert!(contains_call || depth <= max_depth, "No support for chunking up ScriptBufs, depth: {}", depth);
185+
depth += 1;
181186
} else {
182187
call_stack_undo.push(Box::new(builder));
183188
break;
184189
}
185190
}
186191

187192
// Undo the lately added scripts if we are not closing all ifs with them.
193+
// TODO: This is an issue because we may remove way more than necessary.
188194
if num_unclosed_ifs != 0 {
189195
println!("[INFO] Unable to close all ifs. Undoing the added scripts to the point where num_unclosed_ifs was 0.");
190196
num_unclosed_ifs -= num_unclosed_ifs_undo;

0 commit comments

Comments
 (0)