@@ -363,63 +363,6 @@ pub fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
363363 v
364364}
365365
366- /**
367- * Expands a vector in place, initializing the new elements to a given value
368- *
369- * # Arguments
370- *
371- * * v - The vector to grow
372- * * n - The number of elements to add
373- * * initval - The value for the new elements
374- */
375- pub fn grow < T : Copy > ( v : & mut ~[ T ] , n : uint , initval : & T ) {
376- let new_len = v. len ( ) + n;
377- v. reserve_at_least ( new_len) ;
378- let mut i: uint = 0 u;
379-
380- while i < n {
381- v. push ( copy * initval) ;
382- i += 1 u;
383- }
384- }
385-
386- /**
387- * Expands a vector in place, initializing the new elements to the result of
388- * a function
389- *
390- * Function `init_op` is called `n` times with the values [0..`n`)
391- *
392- * # Arguments
393- *
394- * * v - The vector to grow
395- * * n - The number of elements to add
396- * * init_op - A function to call to retreive each appended element's
397- * value
398- */
399- pub fn grow_fn < T > ( v : & mut ~[ T ] , n : uint , op : & fn ( uint ) -> T ) {
400- let new_len = v. len ( ) + n;
401- v. reserve_at_least ( new_len) ;
402- let mut i: uint = 0 u;
403- while i < n {
404- v. push ( op ( i) ) ;
405- i += 1 u;
406- }
407- }
408-
409- /**
410- * Sets the value of a vector element at a given index, growing the vector as
411- * needed
412- *
413- * Sets the element at position `index` to `val`. If `index` is past the end
414- * of the vector, expands the vector by replicating `initval` to fill the
415- * intervening space.
416- */
417- pub fn grow_set < T : Copy > ( v : & mut ~[ T ] , index : uint , initval : & T , val : T ) {
418- let l = v. len ( ) ;
419- if index >= l { grow ( & mut * v, index - l + 1 u, initval) ; }
420- v[ index] = val;
421- }
422-
423366// Functional utilities
424367
425368/// Apply a function to each element of a vector and return the results
@@ -1648,9 +1591,26 @@ impl<T> OwnedVector<T> for ~[T] {
16481591 ( lefts, rights)
16491592 }
16501593
1651- #[ inline]
1594+ /**
1595+ * Expands a vector in place, initializing the new elements to the result of
1596+ * a function
1597+ *
1598+ * Function `init_op` is called `n` times with the values [0..`n`)
1599+ *
1600+ * # Arguments
1601+ *
1602+ * * n - The number of elements to add
1603+ * * init_op - A function to call to retreive each appended element's
1604+ * value
1605+ */
16521606 fn grow_fn ( & mut self , n : uint , op : & fn ( uint ) -> T ) {
1653- grow_fn ( self , n, op) ;
1607+ let new_len = self . len ( ) + n;
1608+ self . reserve_at_least ( new_len) ;
1609+ let mut i: uint = 0 u;
1610+ while i < n {
1611+ self . push ( op ( i) ) ;
1612+ i += 1 u;
1613+ }
16541614 }
16551615}
16561616
@@ -1687,14 +1647,37 @@ impl<T:Copy> OwnedCopyableVector<T> for ~[T] {
16871647 }
16881648 }
16891649
1690- #[ inline]
1650+ /**
1651+ * Expands a vector in place, initializing the new elements to a given value
1652+ *
1653+ * # Arguments
1654+ *
1655+ * * n - The number of elements to add
1656+ * * initval - The value for the new elements
1657+ */
16911658 fn grow ( & mut self , n : uint , initval : & T ) {
1692- grow ( self , n, initval) ;
1659+ let new_len = self . len ( ) + n;
1660+ self . reserve_at_least ( new_len) ;
1661+ let mut i: uint = 0 u;
1662+
1663+ while i < n {
1664+ self . push ( copy * initval) ;
1665+ i += 1 u;
1666+ }
16931667 }
16941668
1695- #[ inline]
1669+ /**
1670+ * Sets the value of a vector element at a given index, growing the vector as
1671+ * needed
1672+ *
1673+ * Sets the element at position `index` to `val`. If `index` is past the end
1674+ * of the vector, expands the vector by replicating `initval` to fill the
1675+ * intervening space.
1676+ */
16961677 fn grow_set ( & mut self , index : uint , initval : & T , val : T ) {
1697- grow_set ( self , index, initval, val) ;
1678+ let l = self . len ( ) ;
1679+ if index >= l { self . grow ( index - l + 1 u, initval) ; }
1680+ self [ index] = val;
16981681 }
16991682}
17001683
0 commit comments