about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-09-18 11:04:21 -0500
committerGitHub <noreply@github.com>2017-09-18 11:04:21 -0500
commit8dae2b0aefb5fc890270a1fe39591d338619d440 (patch)
tree6455cb6b31798f7e12873219f32aba55808f13dc /src/libstd
parentfbf3b8ab8ea98ccc14423cb376a62de6f207fb3e (diff)
parent2787a285bd211ecbf75fd95d990226242005d848 (diff)
downloadrust-8dae2b0aefb5fc890270a1fe39591d338619d440.tar.gz
rust-8dae2b0aefb5fc890270a1fe39591d338619d440.zip
Rollup merge of #44537 - oli-obk:memchr, r=alexcrichton
More `align_offset` things

cc #44488
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/lib.rs1
-rw-r--r--src/libstd/sys_common/memchr.rs9
2 files changed, 4 insertions, 6 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index 1a0f8b8d217..a3eecd46e90 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -242,6 +242,7 @@
 #![feature(allocator_internals)]
 #![feature(allow_internal_unsafe)]
 #![feature(allow_internal_unstable)]
+#![feature(align_offset)]
 #![feature(asm)]
 #![feature(box_syntax)]
 #![feature(cfg_target_has_atomic)]
diff --git a/src/libstd/sys_common/memchr.rs b/src/libstd/sys_common/memchr.rs
index 3824a5fb528..50f998eb486 100644
--- a/src/libstd/sys_common/memchr.rs
+++ b/src/libstd/sys_common/memchr.rs
@@ -65,15 +65,12 @@ pub mod fallback {
         let usize_bytes = mem::size_of::<usize>();
 
         // search up to an aligned boundary
-        let align = (ptr as usize) & (usize_bytes- 1);
-        let mut offset;
-        if align > 0 {
-            offset = cmp::min(usize_bytes - align, len);
+        let mut offset = ptr.align_offset(usize_bytes);
+        if offset > 0 {
+            offset = cmp::min(offset, len);
             if let Some(index) = text[..offset].iter().position(|elt| *elt == x) {
                 return Some(index);
             }
-        } else {
-            offset = 0;
         }
 
         // search the body of the text