Remove a bunch of string builtins. Issue #855

This commit is contained in:
Brian Anderson 2011-08-31 18:47:29 -07:00
parent a7bc386c53
commit d0c509ad1b
5 changed files with 6 additions and 102 deletions

View File

@ -3,13 +3,7 @@ export unsafe_from_bytes;
native "rust" mod rustrt {
type sbuf;
fn str_buf(s: str) -> sbuf;
fn str_byte_len(s: str) -> uint;
fn str_alloc(n_bytes: uint) -> str;
fn str_from_vec(b: &[mutable? u8]) -> str;
fn str_from_cstr(cstr: sbuf) -> str;
fn str_from_buf(buf: sbuf, len: uint) -> str;
fn str_push_byte(s: str, byte: uint) -> str;
fn str_slice(s: str, begin: uint, end: uint) -> str;
fn refcount<T>(s: str) -> uint;
}

View File

@ -140,71 +140,12 @@ vec_alloc_with_data(rust_task *task,
return new (mem) rust_evec(alloc, fill * elt_size, (uint8_t*)d);
}
extern "C" CDECL rust_str*
str_alloc(rust_task *task, size_t n_bytes)
{
rust_str *st = vec_alloc_with_data(task,
n_bytes + 1, // +1 to fit at least ""
1, 1,
(void*)"");
if (!st) {
task->fail();
return NULL;
}
return st;
}
extern "C" CDECL rust_str*
str_push_byte(rust_task* task, rust_str* v, size_t byte)
{
size_t fill = v->fill;
size_t alloc = next_power_of_two(sizeof(rust_evec) + fill + 1);
if (v->ref_count > 1 || v->alloc < alloc) {
v = vec_alloc_with_data(task, fill + 1, fill, 1, (void*)&v->data[0]);
if (!v) {
task->fail();
return NULL;
}
}
else if (v->ref_count != CONST_REFCOUNT) {
v->ref();
}
v->data[fill-1] = (char)byte;
v->data[fill] = '\0';
v->fill++;
return v;
}
extern "C" CDECL rust_str*
str_slice(rust_task* task, rust_str* v, size_t begin, size_t end)
{
size_t len = end - begin;
rust_str *st =
vec_alloc_with_data(task,
len + 1, // +1 to fit at least '\0'
len,
1,
len ? v->data + begin : NULL);
if (!st) {
task->fail();
return NULL;
}
st->data[st->fill++] = '\0';
return st;
}
extern "C" CDECL char const *
str_buf(rust_task *task, rust_str *s)
{
return (char const *)&s->data[0];
}
extern "C" CDECL size_t
str_byte_len(rust_task *task, rust_str *s)
{
return s->fill - 1; // -1 for the '\0' terminator.
}
extern "C" CDECL rust_str *
str_from_vec(rust_task *task, rust_vec **vp)
{
@ -252,29 +193,6 @@ rust_istr_push(rust_task* task, rust_vec** sp, uint8_t byte) {
(*sp)->fill = fill + 1;
}
extern "C" CDECL rust_str *
str_from_cstr(rust_task *task, char *sbuf)
{
size_t len = strlen(sbuf) + 1;
rust_str *st = vec_alloc_with_data(task, len, len, 1, sbuf);
if (!st) {
task->fail();
return NULL;
}
return st;
}
extern "C" CDECL rust_str *
str_from_buf(rust_task *task, char *buf, unsigned int len) {
rust_str *st = vec_alloc_with_data(task, len + 1, len, 1, buf);
if (!st) {
task->fail();
return NULL;
}
st->data[st->fill++] = '\0';
return st;
}
extern "C" CDECL void *
rand_new(rust_task *task)
{

View File

@ -62,16 +62,10 @@ sched_threads
size_of
squareroot
start_task
str_alloc
str_buf
str_byte_len
str_from_buf
str_from_cstr
str_from_vec
vec_reserve_shared
vec_from_buf_shared
str_push_byte
str_slice
task_sleep
task_yield
task_join

View File

@ -118,16 +118,14 @@ fn test_fn() {
}
native "rust" mod native_mod = "" {
fn str_byte_len(s: str) -> uint;
// This isn't actually the signature of str_alloc, but since
// we're not calling it that shouldn't matter
fn str_alloc(s: str) -> uint;
fn do_gc();
fn unsupervise();
}
// FIXME: comparison of native fns
fn test_native_fn() {
assert (native_mod::str_byte_len == native_mod::str_byte_len);
assert (native_mod::str_byte_len != native_mod::str_alloc);
assert (native_mod::do_gc == native_mod::do_gc);
assert (native_mod::do_gc != native_mod::unsupervise);
}
fn test_obj() {

View File

@ -81,7 +81,7 @@ fn test_in_fn_ctxt() {
mod test_native_items {
native "rust" mod rustrt {
#[cfg(bogus)]
fn str_byte_len(s: str) -> uint;
fn str_byte_len(s: str) -> uint;
fn vec_from_buf_shared<T>(ptr: *T, count: uint) -> [T];
fn vec_from_buf_shared<T>(ptr: *T, count: uint) -> [T];
}
}