Skip to content

Commit 164fae9

Browse files
committed
---
yaml --- r: 13621 b: refs/heads/master c: 9bdb2c9 h: refs/heads/master i: 13619: 447e544 v: v3
1 parent 8b3e09a commit 164fae9

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0e5cfd9f339c78384ef3fbcb4d230fa0bb363d54
2+
refs/heads/master: 9bdb2c9e48cefc684b6163249ca816cd96350bde
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libcore/dvec.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl extensions<A> for dvec<A> {
113113
and return a new vector to replace it with.
114114
115115
"]
116+
#[inline(always)]
116117
fn swap(f: fn(-[mut A]) -> [mut A]) {
117118
self.borrow { |v| self.return(f(v)) }
118119
}
@@ -136,11 +137,8 @@ impl extensions<A> for dvec<A> {
136137
impl extensions<A:copy> for dvec<A> {
137138
#[doc = "Append a single item to the end of the list"]
138139
fn push(t: A) {
139-
self.swap { |v|
140-
let mut v <- v;
141-
vec::push(v, t);
142-
v
143-
}
140+
self.check_not_borrowed();
141+
vec::push(self.data, t);
144142
}
145143

146144
#[doc = "Remove and return the last element"]

trunk/src/libcore/sys.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pure fn get_type_desc<T>() -> *type_desc {
5151
}
5252

5353
#[doc = "Returns the size of a type"]
54+
#[inline(always)]
5455
pure fn size_of<T>() -> uint unsafe {
5556
unchecked { rusti::size_of::<T>() }
5657
}

trunk/src/libcore/uint-template/uint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fn iterate(lo: uint, hi: uint, it: fn(uint) -> bool) -> bool {
8181
}
8282

8383
#[doc = "Returns the smallest power of 2 greater than or equal to `n`"]
84+
#[inline(always)]
8485
fn next_power_of_two(n: uint) -> uint {
8586
let halfbits: uint = sys::size_of::<uint>() * 4u;
8687
let mut tmp: uint = n - 1u;

trunk/src/libcore/vec.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ native mod rustrt {
9292
++count: libc::size_t) -> *unsafe::vec_repr;
9393
}
9494

95+
#[abi = "rust-intrinsic"]
96+
native mod rusti {
97+
fn move_val_init<T>(&dst: T, -src: T);
98+
}
99+
95100
#[doc = "A function used to initialize the elements of a vector"]
96101
type init_op<T> = fn(uint) -> T;
97102

@@ -392,17 +397,33 @@ fn pop<T>(&v: [const T]) -> T unsafe {
392397
#[doc = "Append an element to a vector"]
393398
#[inline(always)]
394399
fn push<T>(&v: [const T], +initval: T) {
395-
let ln = v.len();
396400
unsafe {
397-
reserve_at_least(v, ln + 1u);
398-
unsafe::set_len(v, ln + 1u);
399-
let p = ptr::mut_addr_of(v[ln]);
401+
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
402+
let fill = (**repr).fill;
403+
if (**repr).alloc > fill {
404+
let sz = sys::size_of::<T>();
405+
(**repr).fill += sz;
406+
let p = ptr::addr_of((**repr).data);
407+
let p = ptr::offset(p, fill) as *mut T;
408+
rusti::move_val_init(*p, initval);
409+
}
410+
else {
411+
push_slow(v, initval);
412+
}
413+
}
414+
}
400415

401-
// FIXME: for performance, try replacing the memmove and <- with a
402-
// memset and unsafe::forget.
403-
ptr::memset(p, 0, 1u); // needed to stop drop glue from running on
404-
// garbage data.
405-
*p = initval;
416+
fn push_slow<T>(&v: [const T], +initval: T) {
417+
unsafe {
418+
let ln = v.len();
419+
reserve_at_least(v, ln + 1u);
420+
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
421+
let fill = (**repr).fill;
422+
let sz = sys::size_of::<T>();
423+
(**repr).fill += sz;
424+
let p = ptr::addr_of((**repr).data);
425+
let p = ptr::offset(p, fill) as *mut T;
426+
rusti::move_val_init(*p, initval);
406427
}
407428
}
408429

@@ -497,6 +518,7 @@ Sets the element at position `index` to `val`. If `index` is past the end
497518
of the vector, expands the vector by replicating `initval` to fill the
498519
intervening space.
499520
"]
521+
#[inline(always)]
500522
fn grow_set<T: copy>(&v: [mut T], index: uint, initval: T, val: T) {
501523
if index >= len(v) { grow(v, index - len(v) + 1u, initval); }
502524
v[index] = val;

trunk/src/libstd/smallintmap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn mk<T: copy>() -> smallintmap<T> {
1919
Add a value to the map. If the map already contains a value for
2020
the specified key then the original value is replaced.
2121
"]
22+
#[inline(always)]
2223
fn insert<T: copy>(self: smallintmap<T>, key: uint, val: T) {
2324
self.v.grow_set_elt(key, none, some(val));
2425
}
@@ -62,6 +63,7 @@ impl <V: copy> of map::map<uint, V> for smallintmap<V> {
6263
}
6364
sz
6465
}
66+
#[inline(always)]
6567
fn insert(+key: uint, +value: V) -> bool {
6668
let exists = contains_key(self, key);
6769
insert(self, key, value);

trunk/src/test/bench/core-vec-append.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import io::writer_util;
77
fn collect_raw(num: uint) -> [uint] {
88
let mut result = [];
99
for uint::range(0u, num) { |i|
10-
result += [i];
11-
//vec::push(result, i);
10+
//result += [i];
11+
vec::push(result, i);
1212
//result = vec::append(result, [i]);
1313
}
1414
ret result;

0 commit comments

Comments
 (0)