Skip to content

Commit 84c16b3

Browse files
committed
rm utf8 validation
1 parent 348d2b9 commit 84c16b3

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

zjit/bindgen/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,15 @@ fn main() {
462462
bindings.write(Box::new(&mut bindings_string)).expect("Couldn't write bindings!");
463463

464464
// Use i32 for this type since that's what the assembler APIs expect
465-
const JIT_CONSTANTS_NEEDLE: &str = "\npub type jit_bindgen_constants = u32;\n";
466-
const JIT_CONSTANTS_REPLACEMENT: &[u8] = b"\npub type jit_bindgen_constants = i32;\n";
467-
// Yes, this search and replace could be faster, but it's a small file.
468-
let bindings_str = str::from_utf8(bindings_string.as_ref()).expect("bindings should be in UTF-8");
469-
let type_needle_start = bindings_str.find(JIT_CONSTANTS_NEEDLE).expect("bindings should have jit_bindgen_constants");
470-
(&mut bindings_string[type_needle_start..type_needle_start + JIT_CONSTANTS_NEEDLE.len()])
471-
.copy_from_slice(JIT_CONSTANTS_REPLACEMENT);
465+
const JIT_CONSTANTS_NEEDLE: &[u8] = b"pub type jit_bindgen_constants = u32;";
466+
const JIT_CONSTANTS_REPLACEMENT: &[u8] = b"pub type jit_bindgen_constants = i32;";
467+
// Yes, this search-and-replace could be faster, but it's a small file.
468+
for line in bindings_string.as_mut_slice().split_mut(|&byte| byte == b'\n') {
469+
if line == JIT_CONSTANTS_NEEDLE {
470+
line.copy_from_slice(JIT_CONSTANTS_REPLACEMENT);
471+
break;
472+
}
473+
}
472474

473475
// Write out to file
474476
let mut out_path: PathBuf = src_root;

0 commit comments

Comments
 (0)