Skip to content

Commit a5a8bb0

Browse files
committed
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 ```
1 parent 9fb6696 commit a5a8bb0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/core/src/str/validations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub(super) fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
210210
// break if there is a nonascii byte
211211
let zu = contains_nonascii(*block);
212212
let zv = contains_nonascii(*block.offset(1));
213-
if zu | zv {
213+
if zu || zv {
214214
break;
215215
}
216216
}

0 commit comments

Comments
 (0)