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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18978>
This commit is contained in:
LingMan
2022-10-05 22:49:44 +02:00
committed by Marge Bot
parent 4de48a5dd5
commit 9de42613bf
+5 -5
View File
@@ -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);
}
}
}