@@ -363,63 +363,6 @@ pub fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
363
363
v
364
364
}
365
365
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
-
423
366
// Functional utilities
424
367
425
368
/// Apply a function to each element of a vector and return the results
@@ -1648,9 +1591,26 @@ impl<T> OwnedVector<T> for ~[T] {
1648
1591
( lefts, rights)
1649
1592
}
1650
1593
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
+ */
1652
1606
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
+ }
1654
1614
}
1655
1615
}
1656
1616
@@ -1687,14 +1647,37 @@ impl<T:Copy> OwnedCopyableVector<T> for ~[T] {
1687
1647
}
1688
1648
}
1689
1649
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
+ */
1691
1658
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
+ }
1693
1667
}
1694
1668
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
+ */
1696
1677
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;
1698
1681
}
1699
1682
}
1700
1683
0 commit comments