Skip to content

Commit 80c1b5a

Browse files
committed
call by value is more efficient
1 parent 7764e09 commit 80c1b5a

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

src/input.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,20 @@ pub fn from_file(
188188
let mmap = unsafe { self::MmapOptions::new().map(&file)? };
189189
while byte_counter + WIN_LEN <= len {
190190
let chunk = &mmap[byte_counter..byte_counter + WIN_LEN];
191-
sc.launch_scanner(Some(&filename), &byte_counter, &chunk);
191+
sc.launch_scanner(Some(&filename), byte_counter, &chunk);
192192
byte_counter += WIN_STEP;
193193
}
194194
// The last is shorter than WIN_LEN bytes, but can be longer than WIN_STEP
195195
if byte_counter < len {
196196
let chunk = &mmap[byte_counter..len];
197-
sc.launch_scanner(Some(&filename), &byte_counter, &chunk);
197+
sc.launch_scanner(Some(&filename), byte_counter, &chunk);
198198
byte_counter += WIN_STEP;
199199
}
200200

201201
// Now there can be still some bytes left (maximum WIN_OVERLAP bytes)
202202
if byte_counter < len {
203203
let chunk = &mmap[byte_counter..len];
204-
sc.launch_scanner(Some(&filename), &byte_counter, &chunk);
204+
sc.launch_scanner(Some(&filename), byte_counter, &chunk);
205205
}
206206
Ok(())
207207
}
@@ -238,21 +238,21 @@ fn from_stdin(sc: &mut ScannerPool<'_>) -> Result<(), Box<std::io::Error>> {
238238
}
239239
// Handle data.
240240
while data_start + WIN_LEN <= data_end {
241-
sc.launch_scanner(None, &byte_counter, &buf[data_start..data_start + WIN_LEN]);
241+
sc.launch_scanner(None, byte_counter, &buf[data_start..data_start + WIN_LEN]);
242242
data_start += WIN_STEP;
243243
byte_counter += WIN_STEP;
244244
}
245245
}
246246
// The last is shorter than WIN_LEN bytes, but can be longer than WIN_STEP
247247
if data_start < data_end {
248-
sc.launch_scanner(None, &byte_counter, &buf[data_start..data_end]);
248+
sc.launch_scanner(None, byte_counter, &buf[data_start..data_end]);
249249
data_start += WIN_STEP;
250250
byte_counter += WIN_STEP;
251251
}
252252

253253
// Now there can be still some bytes left (maximum WIN_OVERLAP bytes)
254254
if data_start < data_end {
255-
sc.launch_scanner(None, &byte_counter, &buf[data_start..data_end]);
255+
sc.launch_scanner(None, byte_counter, &buf[data_start..data_end]);
256256
}
257257
Ok(())
258258
}

src/scanner.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ impl<'a> ScannerPool<'a> {
153153
pub fn launch_scanner<'b>(
154154
&mut self,
155155
filename: Option<&'static str>,
156-
byte_counter: &usize,
156+
byte_counter: usize,
157157
input_slice: &'b [u8],
158158
) {
159159
ScannerPool::launch_scanner2(
160160
filename,
161-
&byte_counter,
161+
byte_counter,
162162
&input_slice,
163163
&mut self.pool,
164164
&self.tx,
@@ -173,7 +173,7 @@ impl<'a> ScannerPool<'a> {
173173
///
174174
fn launch_scanner2<'b>(
175175
filename: Option<&'static str>,
176-
byte_counter: &usize,
176+
byte_counter: usize,
177177
input_slice: &'b [u8],
178178
pool: &mut Pool,
179179
tx: &SyncSender<FindingCollection>,
@@ -237,7 +237,7 @@ impl<'a> ScannerPool<'a> {
237237
fn scan_window<'b>(
238238
scanner_state: &ScannerState,
239239
filename: Option<&'static str>,
240-
byte_counter: &usize,
240+
byte_counter: usize,
241241
input: &'b [u8],
242242
) -> (FindingCollection, usize) {
243243
// True if `mission.offset` is in the last UTF8_LEN_MAX Bytes of WIN_OVERLAP
@@ -441,7 +441,7 @@ mod tests {
441441
mission: &MISSIONS.v[0],
442442
};
443443

444-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
444+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
445445

446446
assert_eq!(res, expected_fc);
447447
assert_eq!(start, 18);
@@ -467,7 +467,7 @@ mod tests {
467467
mission: &MISSIONS.v[0],
468468
};
469469

470-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
470+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
471471

472472
assert_eq!(res, expected_fc);
473473
assert_eq!(start, 18);
@@ -508,7 +508,7 @@ mod tests {
508508
mission: &MISSIONS.v[0],
509509
};
510510

511-
let (res, mut start) = ScannerPool::scan_window(&ms, None, &start, &inp[..WIN_LEN]);
511+
let (res, mut start) = ScannerPool::scan_window(&ms, None, start, &inp[..WIN_LEN]);
512512

513513
assert_eq!(res, expected_fc);
514514
assert_eq!(start, WIN_LEN);
@@ -534,7 +534,7 @@ mod tests {
534534
mission: &MISSIONS.v[0],
535535
};
536536

537-
let (res, start) = ScannerPool::scan_window(&ms, None, &WIN_STEP, &inp[WIN_STEP..]);
537+
let (res, start) = ScannerPool::scan_window(&ms, None, WIN_STEP, &inp[WIN_STEP..]);
538538
assert_eq!(res, expected_fc);
539539
assert_eq!(start, 17);
540540
}
@@ -565,7 +565,7 @@ mod tests {
565565
mission: &MISSIONS.v[0],
566566
};
567567

568-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
568+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
569569

570570
assert_eq!(res, expected_fc);
571571
assert_eq!(start, 25);
@@ -585,7 +585,7 @@ mod tests {
585585
mission: &MISSIONS.v[0],
586586
};
587587

588-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
588+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
589589

590590
assert_eq!(res, expected_fc);
591591
assert_eq!(start, 4);
@@ -619,7 +619,7 @@ mod tests {
619619
mission: &MISSIONS.v[1],
620620
};
621621

622-
let (res, mut start) = ScannerPool::scan_window(&ms, None, &start, &inp[..WIN_LEN]);
622+
let (res, mut start) = ScannerPool::scan_window(&ms, None, start, &inp[..WIN_LEN]);
623623

624624
assert_eq!(res, expected_fc);
625625
assert_eq!(start, 23);
@@ -642,7 +642,7 @@ mod tests {
642642
ms.offset = start;
643643
ms.completes_last_str = res.last_str_is_incomplete;
644644

645-
let (res, start) = ScannerPool::scan_window(&ms, None, &WIN_STEP, &inp[WIN_STEP..]);
645+
let (res, start) = ScannerPool::scan_window(&ms, None, WIN_STEP, &inp[WIN_STEP..]);
646646

647647
assert_eq!(res, expected_fc);
648648
assert_eq!(start, 9);
@@ -680,7 +680,7 @@ mod tests {
680680
mission: &MISSIONS.v[1],
681681
};
682682

683-
let (res, mut start) = ScannerPool::scan_window(&ms, None, &start, &inp[..WIN_LEN]);
683+
let (res, mut start) = ScannerPool::scan_window(&ms, None, start, &inp[..WIN_LEN]);
684684

685685
assert_eq!(res, expected_fc);
686686
assert_eq!(start, 23);
@@ -703,7 +703,7 @@ mod tests {
703703
ms.offset = start;
704704
ms.completes_last_str = res.last_str_is_incomplete;
705705

706-
let (res, start) = ScannerPool::scan_window(&ms, None, &WIN_STEP, &inp[WIN_STEP..]);
706+
let (res, start) = ScannerPool::scan_window(&ms, None, WIN_STEP, &inp[WIN_STEP..]);
707707

708708
assert_eq!(res, expected_fc);
709709
assert_eq!(start, 9);
@@ -740,7 +740,7 @@ mod tests {
740740
mission: &MISSIONS.v[1],
741741
};
742742

743-
let (res, mut start) = ScannerPool::scan_window(&ms, None, &start, &inp[..WIN_LEN]);
743+
let (res, mut start) = ScannerPool::scan_window(&ms, None, start, &inp[..WIN_LEN]);
744744

745745
assert_eq!(res, expected_fc);
746746
assert_eq!(start, 25);
@@ -758,7 +758,7 @@ mod tests {
758758
ms.offset = start;
759759
ms.completes_last_str = res.last_str_is_incomplete;
760760

761-
let (res, start) = ScannerPool::scan_window(&ms, None, &WIN_STEP, &inp[WIN_STEP..]);
761+
let (res, start) = ScannerPool::scan_window(&ms, None, WIN_STEP, &inp[WIN_STEP..]);
762762

763763
assert_eq!(res, expected_fc);
764764
assert_eq!(start, 9);
@@ -791,7 +791,7 @@ mod tests {
791791
mission: &MISSIONS.v[1],
792792
};
793793

794-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..WIN_LEN]);
794+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..WIN_LEN]);
795795

796796
assert_eq!(res, expected_fc);
797797
assert_eq!(start, 25);
@@ -829,7 +829,7 @@ mod tests {
829829
mission: &MISSIONS.v[0],
830830
};
831831

832-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
832+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
833833

834834
assert_eq!(res, expected_fc);
835835
assert_eq!(start, 17);
@@ -844,7 +844,7 @@ mod tests {
844844
mission: &MISSIONS.v[0],
845845
};
846846

847-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
847+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
848848

849849
assert_eq!(res, expected_fc);
850850
assert_eq!(start, 18);
@@ -883,7 +883,7 @@ mod tests {
883883
mission: &MISSIONS.v[0],
884884
};
885885

886-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
886+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
887887

888888
assert_eq!(res, expected_fc);
889889
assert_eq!(start, 18);
@@ -917,7 +917,7 @@ mod tests {
917917
mission: &MISSIONS.v[0],
918918
};
919919

920-
let (res, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
920+
let (res, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
921921

922922
assert_eq!(res, expected_fc);
923923
assert_eq!(start, 18);
@@ -948,7 +948,7 @@ mod tests {
948948
mission: &MISSIONS.v[0],
949949
};
950950

951-
let (res, mut start) = ScannerPool::scan_window(&ms, None, &start, &inp[..WIN_LEN]);
951+
let (res, mut start) = ScannerPool::scan_window(&ms, None, start, &inp[..WIN_LEN]);
952952

953953
assert_eq!(res, expected_fc);
954954
assert_eq!(start, 25);
@@ -971,7 +971,7 @@ mod tests {
971971
ms.offset = start;
972972
ms.completes_last_str = res.last_str_is_incomplete;
973973

974-
let (res, start) = ScannerPool::scan_window(&ms, None, &WIN_STEP, &inp[WIN_STEP..]);
974+
let (res, start) = ScannerPool::scan_window(&ms, None, WIN_STEP, &inp[WIN_STEP..]);
975975

976976
assert_eq!(res, expected2);
977977
assert_eq!(start, 10);
@@ -1035,7 +1035,7 @@ mod tests {
10351035
//println!("Merger terminated.");
10361036
});
10371037

1038-
sc.launch_scanner(None, &1000usize, &"hallo1234üduüso567890".as_bytes());
1038+
sc.launch_scanner(None, 1000usize, &"hallo1234üduüso567890".as_bytes());
10391039
assert_eq!(sc.scanner_states.v[0].offset, 6);
10401040
//assert_eq!(sc.scanner_states.v[1].offset, 6);
10411041
} // tx drops here
@@ -1072,31 +1072,31 @@ mod tests {
10721072
completes_last_str: false,
10731073
mission: &MISSIONS3.v[0],
10741074
};
1075-
let (res0, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
1075+
let (res0, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
10761076

10771077
let start = 0;
10781078
let ms = ScannerState {
10791079
offset: 0,
10801080
completes_last_str: false,
10811081
mission: &MISSIONS3.v[1],
10821082
};
1083-
let (res1, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
1083+
let (res1, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
10841084

10851085
let start = 0;
10861086
let ms = ScannerState {
10871087
offset: 0,
10881088
completes_last_str: false,
10891089
mission: &MISSIONS3.v[2],
10901090
};
1091-
let (res2, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
1091+
let (res2, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
10921092

10931093
let start = 0;
10941094
let ms = ScannerState {
10951095
offset: 0,
10961096
completes_last_str: false,
10971097
mission: &MISSIONS3.v[3],
10981098
};
1099-
let (res3, start) = ScannerPool::scan_window(&ms, None, &start, &inp[..]);
1099+
let (res3, start) = ScannerPool::scan_window(&ms, None, start, &inp[..]);
11001100

11011101
// To see println! output: cargo test -- --nocapture
11021102
/*

0 commit comments

Comments
 (0)