Skip to content

Commit

Permalink
src/ add ezcheck12d2
Browse files Browse the repository at this point in the history
Add efficiency hack EZCHECK12D2 which combines other
hacks EZCHECK12 and EZCHECKD2 into one iteration over the slice.

Refactor SyslineReader as needed.
  • Loading branch information
jtmoon79 committed Mar 31, 2023
1 parent cf91c1d commit 08738c4
Show file tree
Hide file tree
Showing 5 changed files with 538 additions and 90 deletions.
15 changes: 15 additions & 0 deletions src/bin/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3972,6 +3972,21 @@ fn print_cache_stats_summarysyslinereader(
wide = wide,
widep = WIDEP,
);
// SyslineReader::ezcheck12d2
percent = percent64(
&summarysyslinereader.syslinereader_ezcheck12d2_hit,
&summarysyslinereader.syslinereader_ezcheck12d2_miss,
);
eprintln!(
"{}optimize:SyslineReader::ezcheck12d2 : hit {:wide$}, miss {:wide$}, {:widep$.1}%, largest skipped {}",
indent,
summarysyslinereader.syslinereader_ezcheck12d2_hit,
summarysyslinereader.syslinereader_ezcheck12d2_miss,
percent,
summarysyslinereader.syslinereader_ezcheck12d2_hit_max,
wide = wide,
widep = WIDEP,
);
}

fn print_cache_stats_summaryutmpreader(
Expand Down
73 changes: 70 additions & 3 deletions src/data/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,36 @@ impl fmt::Debug for DateTimeParseInstr<'_> {
}
}

impl DateTimeParseInstr<'_> {
/// wrapper to [`DTFSSet::has_year`]
///
/// [`DTFSSet::has_year`]: crate::data::datetime::DTFSSet#method.has_year
pub const fn has_year(&self) -> bool {
self.dtfs.has_year()
}

/// wrapper to [`DTFSSet::has_year4`]
///
/// [`DTFSSet::has_year4`]: crate::data::datetime::DTFSSet#method.has_year4
pub const fn has_year4(&self) -> bool {
self.dtfs.has_year4()
}

/// wrapper to [`DTFSSet::has_tz`]
///
/// [`DTFSSet::has_tz`]: DTFSSet#method.has_tz
pub const fn has_tz(&self) -> bool {
self.dtfs.has_tz()
}

/// wrapper to [`DTFSSet::has_d2`]
///
/// [`DTFSSet::has_d2`]: crate::data::datetime::DTFSSet#method.has_d2
pub const fn has_d2(&self) -> bool {
self.dtfs.has_d2()
}
}

// `strftime` patterns used in `DTFSSet!` declarations

// TODO: [2022/10/08] refactor for consistent naming of `DTP_*` variables:
Expand Down Expand Up @@ -6877,9 +6907,6 @@ pub fn slice_contains_D2(
slice_: &[u8],
) -> bool {
let mut byte_last_d: bool = false;
if slice_.len() < 2 {
return false;
}
for byte_ in slice_.iter() {
match byte_ {
b'0'
Expand All @@ -6903,3 +6930,43 @@ pub fn slice_contains_D2(

false
}

/// Combination of prior functions `slice_contains_X_2` and
/// `slice_contains_D2`.
///
/// This combined hack check function is more efficient.
///
/// - Returns `true` if `slice_` contains `'1'` or `'2'` (as UTF8 bytes).
/// - Returns `true` if `slice_` contains two consecutive "digit" chars
/// (as UTF8 bytes).
#[inline(always)]
#[allow(non_snake_case)]
pub (crate) fn slice_contains_12_D2(
slice_: &[u8],
) -> bool {
let mut byte_last_d: bool = false;
for byte_ in slice_.iter() {
match byte_ {
b'1'
| b'2' => {
return true;
}
b'0'
| b'3'
| b'4'
| b'5'
| b'6'
| b'7'
| b'8'
| b'9' => {
if byte_last_d {
return true;
}
byte_last_d = true;
},
_ => byte_last_d = false,
}
}

false
}
Loading

0 comments on commit 08738c4

Please sign in to comment.