From 9de42613bfdefecb1f4a3a10a99311f4e80b095c Mon Sep 17 00:00:00 2001 From: LingMan <18294-LingMan@users.noreply.gitlab.freedesktop.org> Date: Wed, 5 Oct 2022 22:49:44 +0200 Subject: [PATCH] rusticl/api: Drop UTF-8 conversion of input source The spec doesn't define any charset for the source code. While the vast majority of inputs are likely to be ASCII (which a subset of UTF-8), it is better not to make assumptions. As a nice side effect this should be a minor speedup. `CString`s can't currently be pushed to, so use a `Vec` as intermediate. Part-of: --- src/gallium/frontends/rusticl/api/program.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gallium/frontends/rusticl/api/program.rs b/src/gallium/frontends/rusticl/api/program.rs index 87e065f4b78..f1e9bd90fa3 100644 --- a/src/gallium/frontends/rusticl/api/program.rs +++ b/src/gallium/frontends/rusticl/api/program.rs @@ -136,16 +136,16 @@ pub fn create_program_with_source( Box::new(unsafe { slice::from_raw_parts(lengths, count as usize) }.iter()) }; - let mut source = String::new(); - // we don't want encoding or any other problems with the source to prevent compilations, so - // just use CString::from_vec_unchecked and to_string_lossy + // We don't want encoding or any other problems with the source to prevent + // compilation, so don't convert this to a Rust `String`. + let mut source = Vec::new(); for (&string_ptr, len) in iter::zip(srcs, lengths) { unsafe { if *len == 0 { - source.push_str(&CStr::from_ptr(string_ptr).to_string_lossy()); + source.extend_from_slice(CStr::from_ptr(string_ptr).to_bytes()); } else { let arr = slice::from_raw_parts(string_ptr.cast(), *len); - source.push_str(&CString::from_vec_unchecked(arr.to_vec()).to_string_lossy()); + source.extend_from_slice(arr); } } }