Skip to content

Commit 19f2cca

Browse files
lilyballemberian
authored andcommitted
---
yaml --- r: 66303 b: refs/heads/master c: 524a92c h: refs/heads/master i: 66301: bfe5501 66299: 01a55c3 66295: 38b0b06 66287: cde4078 66271: f04000e 66239: 4b92f7e 66175: 877fcbf 66047: d585d33 v: v3
1 parent 1dfed5a commit 19f2cca

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,5 +1,5 @@
11
---
2-
refs/heads/master: 35314c93fa07a21aea18548f59886285a303c696
2+
refs/heads/master: 524a92c72ff05613aa5bbd0d806910222741ae2a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/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)