Skip to content

Commit 3e0b4cf

Browse files
committed
Moving raw pointers to Options and Vecs to arrays
1 parent 16fda4a commit 3e0b4cf

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/rust/src/decoder/mod.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ const CCX_DTVCC_MAX_SERVICES: usize = 63;
2525
pub struct Dtvcc<'a> {
2626
pub is_active: bool,
2727
pub active_services_count: u8,
28-
pub services_active: Vec<i32>,
28+
pub services_active: [i32; CCX_DTVCC_MAX_SERVICES],
2929
pub report_enabled: bool,
3030
pub report: &'a mut ccx_decoder_dtvcc_report,
31-
pub decoders: Vec<&'a mut dtvcc_service_decoder>,
32-
pub packet: Vec<u8>,
31+
pub decoders: [Option<&'a mut dtvcc_service_decoder>; CCX_DTVCC_MAX_SERVICES],
32+
pub packet: [u8; CCX_DTVCC_MAX_SERVICES],
3333
pub packet_length: u8,
3434
pub is_header_parsed: bool,
3535
pub last_sequence: i32,
36-
pub encoder: &'a mut encoder_ctx,
36+
pub encoder: Option<&'a mut encoder_ctx>,
3737
pub no_rollup: bool,
3838
pub timing: &'a mut ccx_common_timing_ctx,
3939
}
@@ -44,30 +44,30 @@ impl<'a> Dtvcc<'a> {
4444
let report = unsafe { &mut *opts.report };
4545
report.reset_count = 0;
4646

47-
let decoders = (0..CCX_DTVCC_MAX_SERVICES)
48-
.map(|i| {
49-
if !is_true(opts.services_enabled[i]) {
50-
return unsafe { &mut *std::ptr::null_mut() };
51-
}
47+
const INIT: Option<&mut dtvcc_service_decoder> = None;
48+
let decoders = [INIT; CCX_DTVCC_MAX_SERVICES];
49+
decoders.iter_mut().enumerate().for_each(|(i, val)| {
50+
if !is_true(opts.services_enabled[i]) {
51+
return;
52+
}
5253

53-
let decoder = Box::leak(Box::new(dtvcc_service_decoder {
54-
tv: Box::leak(Box::new(dtvcc_tv_screen {
55-
cc_count: 0,
56-
service_number: i as i32 + 1,
57-
..dtvcc_tv_screen::default()
58-
})),
59-
..dtvcc_service_decoder::default()
60-
}));
54+
let decoder = Box::leak(Box::new(dtvcc_service_decoder {
55+
tv: Box::leak(Box::new(dtvcc_tv_screen {
56+
cc_count: 0,
57+
service_number: i as i32 + 1,
58+
..dtvcc_tv_screen::default()
59+
})),
60+
..dtvcc_service_decoder::default()
61+
}));
6162

62-
decoder.windows.iter_mut().for_each(|w| {
63-
w.memory_reserved = 0;
64-
});
63+
decoder.windows.iter_mut().for_each(|w| {
64+
w.memory_reserved = 0;
65+
});
6566

66-
unsafe { dtvcc_windows_reset(decoder) };
67+
unsafe { dtvcc_windows_reset(decoder) };
6768

68-
decoder
69-
})
70-
.collect();
69+
val = &mut Some(decoder);
70+
});
7171

7272
for i in 0..CCX_DTVCC_MAX_SERVICES {
7373
if !is_true(opts.services_enabled[i]) {
@@ -83,14 +83,14 @@ impl<'a> Dtvcc<'a> {
8383
is_active: false,
8484
no_rollup: is_true(opts.no_rollup),
8585
active_services_count: opts.active_services_count as u8,
86-
services_active: opts.services_enabled.to_vec(),
86+
services_active: opts.services_enabled.clone(),
8787
packet_length: 0,
8888
is_header_parsed: false,
89-
packet: vec![0; CCX_DTVCC_MAX_SERVICES],
89+
packet: [0; CCX_DTVCC_MAX_SERVICES],
9090
last_sequence: CCX_DTVCC_NO_LAST_SEQUENCE,
9191
report_enabled: is_true(opts.print_file_reports),
9292
timing: unsafe { &mut *opts.timing },
93-
encoder: unsafe { &mut *std::ptr::null_mut() },
93+
encoder: None,
9494
}
9595

9696
// notes: import CCX_DTVCC_MAX_SERVICES, initialize the decoders

0 commit comments

Comments
 (0)