Skip to content

Commit 7046fce

Browse files
killerswanbrson
authored andcommitted
---
yaml --- r: 14070 b: refs/heads/try c: 6be25c8 h: refs/heads/master v: v3
1 parent f973421 commit 7046fce

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: d3dfe8758d674d41c3aae116385bcc2b992413ed
5+
refs/heads/try: 6be25c8a0cfe28f032ce2b65f8cb07dd1a1ae148
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/str.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export
9797
as_buf,
9898
//buf,
9999
sbuf,
100+
reserve,
100101

101102
unsafe;
102103

@@ -105,6 +106,7 @@ export
105106
#[abi = "cdecl"]
106107
native mod rustrt {
107108
fn rust_str_push(&s: str, ch: u8);
109+
fn str_reserve_shared(&ss: str, nn: ctypes::size_t);
108110
}
109111

110112
// FIXME: add pure to a lot of functions
@@ -755,6 +757,7 @@ Apply a function to each character
755757
*/
756758
fn map(ss: str, ff: fn(char) -> char) -> str {
757759
let result = "";
760+
reserve(result, byte_len(ss));
758761

759762
chars_iter(ss, {|cc|
760763
str::push_char(result, ff(cc));
@@ -1302,6 +1305,13 @@ An unsafe buffer of bytes. Corresponds to a C char pointer.
13021305
*/
13031306
type sbuf = *u8;
13041307

1308+
// Function: reserve
1309+
//
1310+
// Allocate more memory for a string, up to `nn` + 1 bytes
1311+
fn reserve(&ss: str, nn: uint) {
1312+
rustrt::str_reserve_shared(ss, nn);
1313+
}
1314+
13051315
// Module: unsafe
13061316
//
13071317
// These functions may create invalid UTF-8 strings and eat your baby.

branches/try/src/rt/rust_builtin.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ vec_reserve_shared(type_desc* ty, rust_vec** vp,
105105
reserve_vec_exact(task, vp, n_elts * ty->size);
106106
}
107107

108+
extern "C" CDECL void
109+
str_reserve_shared(rust_vec** sp,
110+
size_t n_elts) {
111+
rust_task *task = rust_task_thread::get_task();
112+
reserve_vec_exact(task, sp, n_elts + 1);
113+
}
114+
108115
/**
109116
* Copies elements in an unsafe buffer to the given interior vector. The
110117
* vector must have size zero.

branches/try/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ shape_log_str
5050
squareroot
5151
start_task
5252
vec_reserve_shared
53+
str_reserve_shared
5354
vec_from_buf_shared
5455
unsupervise
5556
upcall_cmp_type

0 commit comments

Comments
 (0)