Skip to content

Commit b184c97

Browse files
committed
---
yaml --- r: 148179 b: refs/heads/try2 c: 0b3311c h: refs/heads/master i: 148177: 318ba42 148175: 67893ec v: v3
1 parent c3494f7 commit b184c97

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 326e63187ff4490c30ed603158e00c0be58dd162
8+
refs/heads/try2: 0b3311c260812cef6c35b7e99e93516cfc7a3561
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/io/extensions.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
// XXX: Not sure how this should be structured
1414
// XXX: Iteration should probably be considered separately
1515

16+
use container::Container;
1617
use iter::Iterator;
1718
use option::Option;
1819
use io::Reader;
19-
use vec::OwnedVector;
20+
use vec::{OwnedVector, ImmutableVector};
2021

2122
/// An iterator that reads a single byte on each iteration,
2223
/// until `.read_byte()` returns `None`.
@@ -117,16 +118,23 @@ pub fn u64_from_be_bytes(data: &[u8],
117118
start: uint,
118119
size: uint)
119120
-> u64 {
120-
let mut sz = size;
121-
assert!((sz <= 8u));
122-
let mut val = 0_u64;
123-
let mut pos = start;
124-
while sz > 0u {
125-
sz -= 1u;
126-
val += (data[pos] as u64) << ((sz * 8u) as u64);
127-
pos += 1u;
128-
}
129-
return val;
121+
use ptr::{copy_nonoverlapping_memory, offset, mut_offset};
122+
use unstable::intrinsics::from_be64;
123+
use vec::MutableVector;
124+
125+
assert!(size <= 8u);
126+
127+
if data.len() - start < size {
128+
fail!("index out of bounds");
129+
}
130+
131+
let mut buf = [0u8, ..8];
132+
unsafe {
133+
let ptr = offset(data.as_ptr(), start as int);
134+
let out = buf.as_mut_ptr();
135+
copy_nonoverlapping_memory(mut_offset(out, (8 - size) as int), ptr, size);
136+
from_be64(*(out as *i64)) as u64
137+
}
130138
}
131139

132140
#[cfg(test)]

0 commit comments

Comments
 (0)