Make vectors uglier ([]/~). Sorry. Should be temporary. Closes #2725.
This commit is contained in:
@@ -32,7 +32,7 @@ may permit read-only access during iteration or other use.
|
||||
# WARNING
|
||||
|
||||
For maximum performance, this type is implemented using some rather
|
||||
unsafe code. In particular, this innocent looking `[mut A]` pointer
|
||||
unsafe code. In particular, this innocent looking `[mut A]/~` pointer
|
||||
*may be null!* Therefore, it is important you not reach into the
|
||||
data structure manually but instead use the provided extensions.
|
||||
|
||||
@@ -48,27 +48,26 @@ type could only produce 47 million pushes/second.
|
||||
|
||||
"]
|
||||
type dvec<A> = {
|
||||
|
||||
mut data: [mut A]
|
||||
mut data: [mut A]/~
|
||||
};
|
||||
|
||||
#[doc = "Creates a new, empty dvec"]
|
||||
fn dvec<A>() -> dvec<A> {
|
||||
{mut data: [mut]}
|
||||
{mut data: [mut]/~}
|
||||
}
|
||||
|
||||
#[doc = "Creates a new dvec with a single element"]
|
||||
fn from_elt<A>(+e: A) -> dvec<A> {
|
||||
{mut data: [mut e]}
|
||||
{mut data: [mut e]/~}
|
||||
}
|
||||
|
||||
#[doc = "Creates a new dvec with the contents of a vector"]
|
||||
fn from_vec<A>(+v: [mut A]) -> dvec<A> {
|
||||
fn from_vec<A>(+v: [mut A]/~) -> dvec<A> {
|
||||
{mut data: v}
|
||||
}
|
||||
|
||||
#[doc = "Consumes the vector and returns its contents"]
|
||||
fn unwrap<A>(-d: dvec<A>) -> [mut A] {
|
||||
fn unwrap<A>(-d: dvec<A>) -> [mut A]/~ {
|
||||
let {data: v} <- d;
|
||||
ret v;
|
||||
}
|
||||
@@ -84,7 +83,7 @@ impl private_methods<A> for dvec<A> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn borrow<B>(f: fn(-[mut A]) -> B) -> B {
|
||||
fn borrow<B>(f: fn(-[mut A]/~) -> B) -> B {
|
||||
unsafe {
|
||||
let mut data = unsafe::reinterpret_cast(null::<()>());
|
||||
data <-> self.data;
|
||||
@@ -95,7 +94,7 @@ impl private_methods<A> for dvec<A> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn return(-data: [mut A]) {
|
||||
fn return(-data: [mut A]/~) {
|
||||
unsafe {
|
||||
self.data <- data;
|
||||
}
|
||||
@@ -114,7 +113,7 @@ impl extensions<A> for dvec<A> {
|
||||
|
||||
"]
|
||||
#[inline(always)]
|
||||
fn swap(f: fn(-[mut A]) -> [mut A]) {
|
||||
fn swap(f: fn(-[mut A]/~) -> [mut A]/~) {
|
||||
self.borrow { |v| self.return(f(v)) }
|
||||
}
|
||||
|
||||
@@ -128,7 +127,7 @@ impl extensions<A> for dvec<A> {
|
||||
}
|
||||
|
||||
#[doc = "Overwrite the current contents"]
|
||||
fn set(+w: [mut A]) {
|
||||
fn set(+w: [mut A]/~) {
|
||||
self.check_not_borrowed();
|
||||
self.data <- w;
|
||||
}
|
||||
@@ -151,7 +150,7 @@ impl extensions<A> for dvec<A> {
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(data);
|
||||
if data_ptr.is_null() { fail "Recursive use of dvec"; }
|
||||
log(error, "a");
|
||||
self.data <- [mut t] + data;
|
||||
self.data <- [mut t]/~ + data;
|
||||
log(error, "b");
|
||||
}
|
||||
}
|
||||
@@ -219,7 +218,7 @@ impl extensions<A:copy> for dvec<A> {
|
||||
}
|
||||
};
|
||||
|
||||
for ts.each { |t| v += [t] };
|
||||
for ts.each { |t| v += [t]/~ };
|
||||
v
|
||||
}
|
||||
}
|
||||
@@ -229,7 +228,7 @@ impl extensions<A:copy> for dvec<A> {
|
||||
|
||||
See `unwrap()` if you do not wish to copy the contents.
|
||||
"]
|
||||
fn get() -> [A] {
|
||||
fn get() -> [A]/~ {
|
||||
self.borrow { |v|
|
||||
let w = vec::from_mut(copy v);
|
||||
self.return(v);
|
||||
@@ -271,4 +270,4 @@ impl extensions<A:copy> for dvec<A> {
|
||||
fn last() -> A {
|
||||
self.get_elt(self.len() - 1u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user