Skip to content

Commit 071db0c

Browse files
lilyballemberian
authored andcommitted
---
yaml --- r: 63722 b: refs/heads/snap-stage3 c: 524a92c h: refs/heads/master v: v3
1 parent fa9a882 commit 071db0c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 35314c93fa07a21aea18548f59886285a303c696
4+
refs/heads/snap-stage3: 524a92c72ff05613aa5bbd0d806910222741ae2a
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/vec.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,22 @@ pub mod bytes {
22882288
use uint;
22892289
use vec::raw;
22902290
use vec;
2291+
use ptr;
2292+
2293+
/// A trait for operations on mutable operations on `[u8]`
2294+
pub trait MutableByteVector {
2295+
/// Sets all bytes of the receiver to the given value.
2296+
pub fn set_memory(self, value: u8);
2297+
}
2298+
2299+
impl<'self> MutableByteVector for &'self mut [u8] {
2300+
#[inline]
2301+
fn set_memory(self, value: u8) {
2302+
do vec::as_mut_buf(self) |p, len| {
2303+
unsafe { ptr::set_memory(p, value, len) };
2304+
}
2305+
}
2306+
}
22912307

22922308
/// Bytewise string comparison
22932309
pub fn memcmp(a: &~[u8], b: &~[u8]) -> int {
@@ -3941,4 +3957,14 @@ mod tests {
39413957
t!(@[int]);
39423958
t!(~[int]);
39433959
}
3960+
3961+
#[test]
3962+
fn test_bytes_set_memory() {
3963+
use vec::bytes::MutableByteVector;
3964+
let mut values = [1u8,2,3,4,5];
3965+
values.mut_slice(0,5).set_memory(0xAB);
3966+
assert_eq!(values, [0xAB, 0xAB, 0xAB, 0xAB, 0xAB]);
3967+
values.mut_slice(2,4).set_memory(0xFF);
3968+
assert_eq!(values, [0xAB, 0xAB, 0xFF, 0xFF, 0xAB]);
3969+
}
39443970
}

0 commit comments

Comments
 (0)