Skip to content

Commit

Permalink
change vec::view sig to be sound (good catch @bblum)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Sep 27, 2012
1 parent 2340ef9 commit e844e1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,10 @@ impl BytesWriter: Writer {
vec::reserve(&mut buf, count);
unsafe { vec::raw::set_len(buf, count); }
let view = vec::mut_view(buf, self.pos, count);
vec::bytes::memcpy(view, v, v_len);
{
let view = vec::mut_view(buf, self.pos, count);
vec::bytes::memcpy(view, v, v_len);
}
self.pos += v_len;
Expand Down
11 changes: 6 additions & 5 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ pure fn slice<T: Copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
}

/// Return a slice that points into another slice.
pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
pure fn view<T>(v: &r/[T], start: uint, end: uint) -> &r/[T] {
assert (start <= end);
assert (end <= len(v));
do as_imm_buf(v) |p, _len| {
Expand All @@ -351,7 +351,7 @@ pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
}

/// Return a slice that points into another slice.
pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] {
pure fn mut_view<T>(v: &r/[mut T], start: uint, end: uint) -> &r/[mut T] {
assert (start <= end);
assert (end <= len(v));
do as_mut_buf(v) |p, _len| {
Expand All @@ -364,7 +364,8 @@ pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] {
}

/// Return a slice that points into another slice.
pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] {
pure fn const_view<T>(v: &r/[const T], start: uint,
end: uint) -> &r/[const T] {
assert (start <= end);
assert (end <= len(v));
do as_const_buf(v) |p, _len| {
Expand Down Expand Up @@ -1526,7 +1527,7 @@ impl<T: Copy> &[const T]: CopyableVector<T> {
}

trait ImmutableVector<T> {
pure fn view(start: uint, end: uint) -> &[T];
pure fn view(start: uint, end: uint) -> &self/[T];
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U;
pure fn map<U>(f: fn(v: &T) -> U) -> ~[U];
pure fn mapi<U>(f: fn(uint, v: &T) -> U) -> ~[U];
Expand All @@ -1546,7 +1547,7 @@ trait ImmutableEqVector<T: Eq> {
/// Extension methods for vectors
impl<T> &[T]: ImmutableVector<T> {
/// Return a slice that points into another slice.
pure fn view(start: uint, end: uint) -> &[T] {
pure fn view(start: uint, end: uint) -> &self/[T] {
view(self, start, end)
}
/// Reduce a vector from right to left
Expand Down

0 comments on commit e844e1d

Please sign in to comment.