Skip to content

Commit

Permalink
stats: optimize integer type inferencing
Browse files Browse the repository at this point in the history
- just use is_ok() instead of doing if let Ok()
- in if check, short-circuit faster with simpler `s == "0"` check
  • Loading branch information
jqnatividad committed Jun 17, 2024
1 parent 3500454 commit f829e0c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cmd/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,8 +1584,8 @@ impl FieldType {

if let Ok(s) = simdutf8::basic::from_utf8(sample) {
// Check for integer, with leading zero check for strings like zip codes
if let Ok(_int_val) = atoi_simd::parse::<i64>(s.as_bytes()) {
if !s.starts_with('0') || s == "0" {
if atoi_simd::parse::<i64>(s.as_bytes()).is_ok() {
if s == "0" || !s.starts_with('0') {
return (FieldType::TInteger, None);
}
// If starts with '0' but not "0", it's a string
Expand Down

0 comments on commit f829e0c

Please sign in to comment.