Skip to content

Commit

Permalink
Merge pull request #1118 from laxjesse/split_once_in_lsn_from_str
Browse files Browse the repository at this point in the history
use `split_once` instead of `split` to parse lsn strings
  • Loading branch information
sfackler authored Mar 13, 2024
2 parents 270a29b + 9743630 commit e528e01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions postgres-types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## Unreleased

### Changed

* `FromStr` implementation for `PgLsn` no longer allocates a `Vec` when splitting an lsn string on it's `/`.

## v0.2.6 - 2023-08-19

### Fixed
Expand Down
18 changes: 8 additions & 10 deletions postgres-types/src/pg_lsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ impl FromStr for PgLsn {
type Err = ParseLsnError;

fn from_str(lsn_str: &str) -> Result<Self, Self::Err> {
let split: Vec<&str> = lsn_str.split('/').collect();
if split.len() == 2 {
let (hi, lo) = (
u64::from_str_radix(split[0], 16).map_err(|_| ParseLsnError(()))?,
u64::from_str_radix(split[1], 16).map_err(|_| ParseLsnError(()))?,
);
Ok(PgLsn((hi << 32) | lo))
} else {
Err(ParseLsnError(()))
}
let Some((split_hi, split_lo)) = lsn_str.split_once('/') else {
return Err(ParseLsnError(()));
};
let (hi, lo) = (
u64::from_str_radix(split_hi, 16).map_err(|_| ParseLsnError(()))?,
u64::from_str_radix(split_lo, 16).map_err(|_| ParseLsnError(()))?,
);
Ok(PgLsn((hi << 32) | lo))
}
}

Expand Down

0 comments on commit e528e01

Please sign in to comment.