Skip to content

Commit

Permalink
remove to_string()
Browse files Browse the repository at this point in the history
  • Loading branch information
Weijun-H committed Sep 12, 2023
1 parent fcca059 commit 82962e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
10 changes: 5 additions & 5 deletions arrow-json/src/reader/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ macro_rules! primitive_parse {
fn parse(s: &[u8]) -> Option<Self> {
match std::str::from_utf8(s) {
Ok(s) => {
if let Ok(res) = s.to_string().parse::<$t>() {
if let Ok(res) = s.parse::<$t>() {
Some(res)
} else {
return s.to_string().parse::<f64>().ok().and_then(NumCast::from)
return s.parse::<f64>().ok().and_then(NumCast::from)
}
}
Err(_) => None,
Expand All @@ -64,7 +64,7 @@ primitive_parse!(i8, i16, i32, i64, u8, u16, u32, u64);
impl ParseJsonNumber for f16 {
fn parse(s: &[u8]) -> Option<Self> {
match std::str::from_utf8(s) {
Ok(s) => s.to_string().parse::<f16>().ok(),
Ok(s) => s.parse::<f16>().ok(),
Err(_) => None,
}
}
Expand All @@ -73,7 +73,7 @@ impl ParseJsonNumber for f16 {
impl ParseJsonNumber for f32 {
fn parse(s: &[u8]) -> Option<Self> {
match std::str::from_utf8(s) {
Ok(s) => s.to_string().parse::<f32>().ok(),
Ok(s) => s.parse::<f32>().ok(),
Err(_) => None,
}
}
Expand All @@ -82,7 +82,7 @@ impl ParseJsonNumber for f32 {
impl ParseJsonNumber for f64 {
fn parse(s: &[u8]) -> Option<Self> {
match std::str::from_utf8(s) {
Ok(s) => s.to_string().parse::<f64>().ok(),
Ok(s) => s.parse::<f64>().ok(),
Err(_) => None,
}
}
Expand Down
26 changes: 9 additions & 17 deletions arrow-json/src/reader/timestamp_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,15 @@ where
}
TapeElement::Number(idx) => {
let s = tape.get_string(idx);
let b = s.as_bytes();
let value = match std::str::from_utf8(b) {
Ok(s) => s
.parse::<i64>()
.or_else(|_| s.parse::<f64>().map(|x| x as i64))
.map_err(|_| {
ArrowError::JsonError(format!(
"failed to parse {s} as {}",
self.data_type
))
}),
Err(_) => Err(ArrowError::JsonError(format!(
"failed to parse {s} as {}",
self.data_type
))),
}?;

let value = s
.parse::<i64>()
.or_else(|_| s.parse::<f64>().map(|x| x as i64))
.map_err(|_| {
ArrowError::JsonError(format!(
"failed to parse {s} as {}",
self.data_type
))
})?;
builder.append_value(value)
}
_ => return Err(tape.error(*p, "primitive")),
Expand Down

0 comments on commit 82962e0

Please sign in to comment.