@@ -104,16 +104,26 @@ impl InstructionSet {
104
104
let mut current_idx = start_idx;
105
105
106
106
loop {
107
+ // if we have calculated all buffer bounds, break
107
108
if current_idx >= self . binary . len ( ) - 1 {
108
109
break ;
109
110
}
110
111
112
+ // set current_idx to starting index
113
+ current_idx = start_idx;
114
+
115
+ // otherwise we'll keep the maximum end bound (e.g. current_idx + 4096)
111
116
let max_end_idx = ( start_idx + max_chunk_size) . min ( self . binary . len ( ) - 1 ) ; // max end bound
112
- let mut last_valid_max = current_idx; // last valid end bound
117
+ let mut last_valid_max = current_idx; // last valid end bound, we'll initialise
118
+ // this to the current index
113
119
120
+ // while we're within the buffer bounds, keep incrementing the current_idx
114
121
while current_idx < max_end_idx {
122
+ if ( current_idx > 1 ) { last_valid_max = current_idx - 1 ; } // keep reference to last valid max here
123
+
124
+ // then we "test the waters" by increment current_idx, this COULD be reset if
125
+ // it goes over the max_end_idx
115
126
current_idx += 4 ;
116
-
117
127
if self . get_binary ( ) [ current_idx] == 0x0C {
118
128
current_idx += 1 ;
119
129
} else if self . get_binary ( ) [ current_idx] == 0x0A {
@@ -133,16 +143,15 @@ impl InstructionSet {
133
143
} else {
134
144
return Err ( InstructionError :: IncompleteInstructions ( self . get_binary ( ) [ current_idx] ) ) ;
135
145
}
136
-
137
-
138
- last_valid_max = current_idx - 1 ;
139
146
}
140
147
141
148
chunk_bounds. push ( ( start_idx, last_valid_max) ) ;
149
+ println ! ( "added: {} {}" , start_idx, last_valid_max) ;
142
150
start_idx = last_valid_max + 1 ;
143
-
144
151
}
145
152
153
+ println ! ( "Buffer bounds: {:?}" , chunk_bounds) ;
154
+
146
155
Ok ( chunk_bounds)
147
156
} )
148
157
}
0 commit comments