Skip to content

Commit

Permalink
Rewrite resource_path_to_string for a small code size improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Aug 18, 2021
1 parent 19b6309 commit fd18830
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions provider/blob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde = { version = "1.0", default-features = false, features = ["alloc"] }
postcard = { version = "0.7.0" }
erased-serde = { version = "0.3", default-features = false, features = ["alloc"] }
litemap = { version = "0.2.0", path = "../../utils/litemap/", features = ["serde"] }
writeable = { path = "../../utils/writeable" }

# For the export feature
log = { version = "0.4", optional = true }
Expand Down
13 changes: 7 additions & 6 deletions provider/blob/src/path_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::string::String;
use icu_provider::prelude::*;
use writeable::Writeable;

pub fn resource_path_to_string(resource_path: &ResourcePath) -> String {
let key_components = resource_path.key.get_components();
let opt_components = resource_path.options.get_components();
let all_components: Vec<&str> = key_components.iter().chain(opt_components.iter()).collect();
"/".to_string() + &all_components.join("/")
let mut output = String::with_capacity(resource_path.write_len().capacity() + 1);
output.push('/');
resource_path.write_to(&mut output)
.expect("impl Write for String is infallible");
output
}

0 comments on commit fd18830

Please sign in to comment.