about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro.albini@ferrous-systems.com>2021-10-27 13:03:55 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2021-10-27 17:00:49 +0200
commita5a8bb012540c23a9b4ab5a38bc7f75d5ebaba60 (patch)
treedb73a31a4a7af8edd49bf0592f85c6180ef8c87f
parent9fb66969e38f1ce4b269f9506faf7ebc161ececa (diff)
downloadrust-a5a8bb012540c23a9b4ab5a38bc7f75d5ebaba60.tar.gz
rust-a5a8bb012540c23a9b4ab5a38bc7f75d5ebaba60.zip
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
```
-rw-r--r--library/core/src/str/validations.rs2
1 files changed, 1 insertions, 1 deletions
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;
                         }
                     }