-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve ChainId implementation; this is API breaking change
ChainId::new allocates a new String so there’s no point in passing ownership of name argument. The constructor can accept it as a str slice without loss of functionality. This reduces allocations when creating ids since caller no longer has to have an owned string. Replace From implementations with TryFrom implementations. Conversion now fails if string is not in an epoch format. There’s still a way to construct an identifier without epoch format if it comes from tendermint::chain::Id (or by using ChainId::new with zero version; behaviour of that might change). And since there’s From implementation available, also get rid of ChainId::from_string. Optimise epoch format parsing. `from_string` used to check if argument was in epoch format and then call `chain_version` which did it again. To avoid duplicating work, introduce `split_chain_id` method which does the parsing and returns result which includes all the information callers might want. Similarly, calling `split` and collecting values into a vector is wasteful if all we need is the last token. Furthermore, regexes are quite a heavy machinery for the task of checking if string ends with a number. To address that, use `split_last` and parse the number to check if it’s valid.
- Loading branch information
Showing
9 changed files
with
156 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.