From a5a8bb012540c23a9b4ab5a38bc7f75d5ebaba60 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 27 Oct 2021 13:03:55 +0200 Subject: [PATCH] replace `|` with `||` in string validation Using short-circuiting operators makes it easier to perform some kinds of source code analysis, like MC/DC code coverage (a requirement in safety-critical environments). The optimized x86_64 assembly is equivalent between the old and new versions. Old assembly of that condition: ``` mov rax, qword ptr [rdi + rdx + 8] or rax, qword ptr [rdi + rdx] test rax, r9 je .LBB0_7 ``` New assembly of that condition: ``` mov rax, qword ptr [rdi + rdx] or rax, qword ptr [rdi + rdx + 8] test rax, r8 je .LBB0_7 ``` --- library/core/src/str/validations.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/str/validations.rs b/library/core/src/str/validations.rs index 093c9c37b60..f2d1c737808 100644 --- a/library/core/src/str/validations.rs +++ b/library/core/src/str/validations.rs @@ -210,7 +210,7 @@ pub(super) fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> { // break if there is a nonascii byte let zu = contains_nonascii(*block); let zv = contains_nonascii(*block.offset(1)); - if zu | zv { + if zu || zv { break; } }