Skip to content

Commit 575c417

Browse files
ericktgraydon
authored andcommitted
---
yaml --- r: 22675 b: refs/heads/master c: 9d4aab8 h: refs/heads/master i: 22673: 30a1d29 22671: ca5e86a v: v3
1 parent 3ce769b commit 575c417

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
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: a762c725b523a669159b68d42490668b0a2cc1d6
2+
refs/heads/master: 9d4aab80a718a84a03c379e98a7a4f812822e347
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/vec.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export init;
2727
export last;
2828
export last_opt;
2929
export slice;
30-
export view;
30+
export view, mut_view, const_view;
3131
export split;
3232
export splitn;
3333
export rsplit;
@@ -325,6 +325,30 @@ pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
325325
}
326326
}
327327

328+
/// Return a slice that points into another slice.
329+
pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] {
330+
assert (start <= end);
331+
assert (end <= len(v));
332+
do unpack_slice(v) |p, _len| {
333+
unsafe {
334+
::unsafe::reinterpret_cast(
335+
(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
336+
}
337+
}
338+
}
339+
340+
/// Return a slice that points into another slice.
341+
pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] {
342+
assert (start <= end);
343+
assert (end <= len(v));
344+
do unpack_slice(v) |p, _len| {
345+
unsafe {
346+
::unsafe::reinterpret_cast(
347+
(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
348+
}
349+
}
350+
}
351+
328352
/// Split the vector `v` by applying each element against the predicate `f`.
329353
fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] {
330354
let ln = len(v);

0 commit comments

Comments
 (0)