vec: avoid ptrtoint
/inttoptr
in the iterators
This results in throwing away alias analysis information, because LLVM does *not* implement reasoning about these conversions yet. We specialize zero-size types since a `getelementptr` offset will return us the same pointer, making it broken as a simple counter.
This commit is contained in:
parent
8f9bbc476d
commit
f23fb19ee5
@ -849,10 +849,15 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
|
||||
fn iter(self) -> VecIterator<'self, T> {
|
||||
unsafe {
|
||||
let p = vec::raw::to_ptr(self);
|
||||
VecIterator{ptr: p,
|
||||
end: (p as uint + self.len() *
|
||||
sys::nonzero_size_of::<T>()) as *T,
|
||||
lifetime: cast::transmute(p)}
|
||||
if sys::size_of::<T>() == 0 {
|
||||
VecIterator{ptr: p,
|
||||
end: (p as uint + self.len()) as *T,
|
||||
lifetime: cast::transmute(p)}
|
||||
} else {
|
||||
VecIterator{ptr: p,
|
||||
end: p.offset(self.len() as int),
|
||||
lifetime: cast::transmute(p)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1826,10 +1831,15 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
|
||||
fn mut_iter(self) -> VecMutIterator<'self, T> {
|
||||
unsafe {
|
||||
let p = vec::raw::to_mut_ptr(self);
|
||||
VecMutIterator{ptr: p,
|
||||
end: (p as uint + self.len() *
|
||||
sys::nonzero_size_of::<T>()) as *mut T,
|
||||
lifetime: cast::transmute(p)}
|
||||
if sys::size_of::<T>() == 0 {
|
||||
VecMutIterator{ptr: p,
|
||||
end: (p as uint + self.len()) as *mut T,
|
||||
lifetime: cast::transmute(p)}
|
||||
} else {
|
||||
VecMutIterator{ptr: p,
|
||||
end: p.offset(self.len() as int),
|
||||
lifetime: cast::transmute(p)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user