File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
8
8
## Unreleased
9
9
10
10
- Add ` start() ` and ` end() ` method to the ` Region ` trait.
11
+ - Much faster ` OverlapIterator ` .
11
12
12
13
## [ 0.3.1] - 2023-12-04
13
14
Original file line number Diff line number Diff line change @@ -30,18 +30,15 @@ where
30
30
type Item = ( & ' a [ u8 ] , R , u32 ) ;
31
31
32
32
fn next ( & mut self ) -> Option < Self :: Item > {
33
+ let mem_start = self . base_address ;
34
+ let mem_end = self . base_address + self . memory . len ( ) as u32 ;
33
35
while let Some ( region) = self . regions . next ( ) {
34
- // TODO: This might be possible to do in a smarter way?
35
- let mut block_range = ( 0 ..self . memory . len ( ) )
36
- . skip_while ( |index| !region. contains ( self . base_address + * index as u32 ) )
37
- . take_while ( |index| region. contains ( self . base_address + * index as u32 ) ) ;
38
- if let Some ( start) = block_range. next ( ) {
39
- let end = block_range. last ( ) . unwrap_or ( start) + 1 ;
40
- return Some ( (
41
- & self . memory [ start..end] ,
42
- region,
43
- self . base_address + start as u32 ,
44
- ) ) ;
36
+ if mem_start < region. end ( ) && mem_end >= region. start ( ) {
37
+ let addr_start = core:: cmp:: max ( mem_start, region. start ( ) ) ;
38
+ let addr_end = core:: cmp:: min ( mem_end, region. end ( ) ) ;
39
+ let start = ( addr_start - self . base_address ) as usize ;
40
+ let end = ( addr_end - self . base_address ) as usize ;
41
+ return Some ( ( & self . memory [ start..end] , region, addr_start) ) ;
45
42
}
46
43
}
47
44
None
You can’t perform that action at this time.
0 commit comments