From 39efe50311e459a2011d0abd4d06e1147ca38509 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 1 Aug 2023 12:21:40 +0200 Subject: refactor(tvix/nix-compat/derivation/escape): move to Vec We only need bstr::ByteSlice to be able to use replace, it doesn't need to return a BString. Change-Id: I811948436fb89652e880970c2c05356183f3e439 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9084 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: raitobezarius --- tvix/nix-compat/src/derivation/escape.rs | 10 +++++----- tvix/nix-compat/src/derivation/write.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tvix/nix-compat/src') diff --git a/tvix/nix-compat/src/derivation/escape.rs b/tvix/nix-compat/src/derivation/escape.rs index 8c2c6fce07..06b550bbf0 100644 --- a/tvix/nix-compat/src/derivation/escape.rs +++ b/tvix/nix-compat/src/derivation/escape.rs @@ -1,7 +1,7 @@ -use bstr::{BString, ByteSlice}; +use bstr::ByteSlice; /// Escapes a byte sequence. Does not add surrounding quotes. -pub fn escape_bstr>(s: P) -> BString { +pub fn escape_bytes>(s: P) -> Vec { let mut s: Vec = s.as_ref().to_vec(); s = s.replace(b"\\", b"\\\\"); @@ -10,18 +10,18 @@ pub fn escape_bstr>(s: P) -> BString { s = s.replace(b"\t", b"\\t"); s = s.replace(b"\"", b"\\\""); - s.into() + s } #[cfg(test)] mod tests { - use super::escape_bstr; + use super::escape_bytes; use test_case::test_case; #[test_case(b"", b""; "empty")] #[test_case(b"\"", b"\\\""; "doublequote")] #[test_case(b":", b":"; "colon")] fn escape(input: &[u8], expected: &[u8]) { - assert_eq!(expected, escape_bstr(input)) + assert_eq!(expected, escape_bytes(input)) } } diff --git a/tvix/nix-compat/src/derivation/write.rs b/tvix/nix-compat/src/derivation/write.rs index d84992a3cb..538183ac65 100644 --- a/tvix/nix-compat/src/derivation/write.rs +++ b/tvix/nix-compat/src/derivation/write.rs @@ -3,7 +3,7 @@ //! //! [ATerm]: http://program-transformation.org/Tools/ATermFormat.html -use crate::derivation::escape::escape_bstr; +use crate::derivation::escape::escape_bytes; use crate::derivation::output::Output; use bstr::BString; use std::{ @@ -42,7 +42,7 @@ pub(crate) fn write_field>( if !escape { writer.write_all(s.as_ref())?; } else { - writer.write_all(&escape_bstr(s.as_ref()))?; + writer.write_all(&escape_bytes(s.as_ref()))?; } write_char(writer, QUOTE)?; -- cgit 1.4.1