mirror of
https://github.com/nushell/nushell.git
synced 2025-04-16 01:08:21 +02:00
Speedup unit parse (#4598)
* Compact nuon tables * Speed up unit parsing a bit
This commit is contained in:
parent
31925c3d40
commit
3e8a41fbc9
@ -1710,6 +1710,8 @@ pub fn parse_duration(
|
|||||||
let bytes = working_set.get_span_contents(span);
|
let bytes = working_set.get_span_contents(span);
|
||||||
let token = String::from_utf8_lossy(bytes).to_string();
|
let token = String::from_utf8_lossy(bytes).to_string();
|
||||||
|
|
||||||
|
let upper = token.to_uppercase();
|
||||||
|
|
||||||
let unit_groups = [
|
let unit_groups = [
|
||||||
(Unit::Nanosecond, "NS", None),
|
(Unit::Nanosecond, "NS", None),
|
||||||
(Unit::Microsecond, "US", Some((Unit::Nanosecond, 1000))),
|
(Unit::Microsecond, "US", Some((Unit::Nanosecond, 1000))),
|
||||||
@ -1720,11 +1722,8 @@ pub fn parse_duration(
|
|||||||
(Unit::Day, "DAY", Some((Unit::Minute, 1440))),
|
(Unit::Day, "DAY", Some((Unit::Minute, 1440))),
|
||||||
(Unit::Week, "WK", Some((Unit::Day, 7))),
|
(Unit::Week, "WK", Some((Unit::Day, 7))),
|
||||||
];
|
];
|
||||||
if let Some(unit) = unit_groups
|
if let Some(unit) = unit_groups.iter().find(|&x| upper.ends_with(x.1)) {
|
||||||
.iter()
|
let mut lhs = token;
|
||||||
.find(|&x| token.to_uppercase().ends_with(x.1))
|
|
||||||
{
|
|
||||||
let mut lhs = token.clone();
|
|
||||||
for _ in 0..unit.1.len() {
|
for _ in 0..unit.1.len() {
|
||||||
lhs.pop();
|
lhs.pop();
|
||||||
}
|
}
|
||||||
@ -1806,6 +1805,8 @@ pub fn parse_filesize(
|
|||||||
let bytes = working_set.get_span_contents(span);
|
let bytes = working_set.get_span_contents(span);
|
||||||
let token = String::from_utf8_lossy(bytes).to_string();
|
let token = String::from_utf8_lossy(bytes).to_string();
|
||||||
|
|
||||||
|
let upper = token.to_uppercase();
|
||||||
|
|
||||||
let unit_groups = [
|
let unit_groups = [
|
||||||
(Unit::Kilobyte, "KB", Some((Unit::Byte, 1000))),
|
(Unit::Kilobyte, "KB", Some((Unit::Byte, 1000))),
|
||||||
(Unit::Megabyte, "MB", Some((Unit::Kilobyte, 1000))),
|
(Unit::Megabyte, "MB", Some((Unit::Kilobyte, 1000))),
|
||||||
@ -1819,11 +1820,8 @@ pub fn parse_filesize(
|
|||||||
(Unit::Pebibyte, "PIB", Some((Unit::Tebibyte, 1024))),
|
(Unit::Pebibyte, "PIB", Some((Unit::Tebibyte, 1024))),
|
||||||
(Unit::Byte, "B", None),
|
(Unit::Byte, "B", None),
|
||||||
];
|
];
|
||||||
if let Some(unit) = unit_groups
|
if let Some(unit) = unit_groups.iter().find(|&x| upper.ends_with(x.1)) {
|
||||||
.iter()
|
let mut lhs = token;
|
||||||
.find(|&x| token.to_uppercase().ends_with(x.1))
|
|
||||||
{
|
|
||||||
let mut lhs = token.clone();
|
|
||||||
for _ in 0..unit.1.len() {
|
for _ in 0..unit.1.len() {
|
||||||
lhs.pop();
|
lhs.pop();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user