@@ -343,41 +343,6 @@ pub fn consume_reverse<T>(mut v: ~[T], f: &fn(uint, v: T)) {
343343 }
344344}
345345
346- /**
347- * Remove consecutive repeated elements from a vector; if the vector is
348- * sorted, this removes all duplicates.
349- */
350- pub fn dedup< T : Eq > ( v : & mut ~[ T ] ) {
351- unsafe {
352- if v. len ( ) < 1 { return ; }
353- let mut last_written = 0 ;
354- let mut next_to_read = 1 ;
355- do as_mut_buf( * v) |p, ln| {
356- // last_written < next_to_read <= ln
357- while next_to_read < ln {
358- // last_written < next_to_read < ln
359- if * ptr:: mut_offset ( p, next_to_read) ==
360- * ptr:: mut_offset ( p, last_written) {
361- ptr:: replace_ptr ( ptr:: mut_offset ( p, next_to_read) ,
362- intrinsics:: uninit ( ) ) ;
363- } else {
364- last_written += 1 ;
365- // last_written <= next_to_read < ln
366- if next_to_read != last_written {
367- ptr:: swap_ptr ( ptr:: mut_offset ( p, last_written) ,
368- ptr:: mut_offset ( p, next_to_read) ) ;
369- }
370- }
371- // last_written <= next_to_read < ln
372- next_to_read += 1 ;
373- // last_written < next_to_read <= ln
374- }
375- }
376- // last_written < next_to_read == ln
377- raw:: set_len ( v, last_written + 1 ) ;
378- }
379- }
380-
381346// Appending
382347
383348/// Iterates over the `rhs` vector, copying each element and appending it to the
@@ -1734,14 +1699,44 @@ impl<T:Copy> OwnedCopyableVector<T> for ~[T] {
17341699}
17351700
17361701#[ allow( missing_doc) ]
1737- trait OwnedEqVector < T : Eq > {
1702+ pub trait OwnedEqVector < T : Eq > {
17381703 fn dedup ( & mut self ) ;
17391704}
17401705
17411706impl < T : Eq > OwnedEqVector < T > for ~[ T ] {
1742- #[ inline]
1743- fn dedup ( & mut self ) {
1744- dedup ( self )
1707+ /**
1708+ * Remove consecutive repeated elements from a vector; if the vector is
1709+ * sorted, this removes all duplicates.
1710+ */
1711+ pub fn dedup ( & mut self ) {
1712+ unsafe {
1713+ if self . len ( ) == 0 { return ; }
1714+ let mut last_written = 0 ;
1715+ let mut next_to_read = 1 ;
1716+ do as_mut_buf( * self ) |p, ln| {
1717+ // last_written < next_to_read <= ln
1718+ while next_to_read < ln {
1719+ // last_written < next_to_read < ln
1720+ if * ptr:: mut_offset ( p, next_to_read) ==
1721+ * ptr:: mut_offset ( p, last_written) {
1722+ ptr:: replace_ptr ( ptr:: mut_offset ( p, next_to_read) ,
1723+ intrinsics:: uninit ( ) ) ;
1724+ } else {
1725+ last_written += 1 ;
1726+ // last_written <= next_to_read < ln
1727+ if next_to_read != last_written {
1728+ ptr:: swap_ptr ( ptr:: mut_offset ( p, last_written) ,
1729+ ptr:: mut_offset ( p, next_to_read) ) ;
1730+ }
1731+ }
1732+ // last_written <= next_to_read < ln
1733+ next_to_read += 1 ;
1734+ // last_written < next_to_read <= ln
1735+ }
1736+ }
1737+ // last_written < next_to_read == ln
1738+ raw:: set_len ( self , last_written + 1 ) ;
1739+ }
17451740 }
17461741}
17471742
0 commit comments