aboutsummaryrefslogtreecommitdiff
path: root/nix-rust/src/c.rs
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-12-10 20:48:36 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-12-10 22:15:20 +0100
commitf800d450b78091835ab7ca67847d76e75d877a24 (patch)
tree45f0f2677cda3c3ed484c5dd28c0a69208edab44 /nix-rust/src/c.rs
parentf64b58b45e86e15f64aa2dff67436c2d6fe4a4d8 (diff)
Speed up StorePath::to_string()
1.81% -> 0.56%
Diffstat (limited to 'nix-rust/src/c.rs')
-rw-r--r--nix-rust/src/c.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/nix-rust/src/c.rs b/nix-rust/src/c.rs
index 4c1724eb3..19e737a88 100644
--- a/nix-rust/src/c.rs
+++ b/nix-rust/src/c.rs
@@ -1,6 +1,7 @@
use super::{
error,
foreign::{self, CBox},
+ store::path,
store::StorePath,
util,
};
@@ -53,8 +54,12 @@ pub unsafe extern "C" fn ffi_StorePath_drop(self_: *mut StorePath) {
}
#[no_mangle]
-pub extern "C" fn ffi_StorePath_to_string(self_: &StorePath) -> String {
- format!("{}", self_)
+pub extern "C" fn ffi_StorePath_to_string(self_: &StorePath) -> Vec<u8> {
+ let mut buf = vec![0; path::STORE_PATH_HASH_CHARS + 1 + self_.name.name().len()];
+ util::base32::encode_into(self_.hash.hash(), &mut buf[0..path::STORE_PATH_HASH_CHARS]);
+ buf[path::STORE_PATH_HASH_CHARS] = b'-';
+ buf[path::STORE_PATH_HASH_CHARS + 1..].clone_from_slice(self_.name.name().as_bytes());
+ buf
}
#[no_mangle]