Merge remote-tracking branch 'erickt/incoming'
This commit is contained in:
commit
a0de6b6d5f
6 changed files with 46 additions and 87 deletions
|
@ -663,24 +663,21 @@ type MemBuffer = @{buf: DVec<u8>, mut pos: uint};
|
||||||
|
|
||||||
impl MemBuffer: Writer {
|
impl MemBuffer: Writer {
|
||||||
fn write(v: &[const u8]) {
|
fn write(v: &[const u8]) {
|
||||||
// Fast path.
|
do self.buf.swap |buf| {
|
||||||
let vlen = vec::len(v);
|
let mut buf <- buf;
|
||||||
let buf_len = self.buf.len();
|
let v_len = v.len();
|
||||||
if self.pos == buf_len {
|
let buf_len = buf.len();
|
||||||
self.buf.push_all(v);
|
|
||||||
self.pos += vlen;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME #2004--use memcpy here?
|
let count = uint::max(&buf_len, &(self.pos + v_len));
|
||||||
let mut pos = self.pos, vpos = 0u;
|
vec::reserve(buf, count);
|
||||||
while vpos < vlen && pos < buf_len {
|
unsafe { vec::unsafe::set_len(buf, count); }
|
||||||
self.buf.set_elt(pos, copy v[vpos]);
|
|
||||||
pos += 1u;
|
vec::u8::memcpy(vec::mut_view(buf, self.pos, count), v, v_len);
|
||||||
vpos += 1u;
|
|
||||||
|
self.pos += v_len;
|
||||||
|
|
||||||
|
buf
|
||||||
}
|
}
|
||||||
self.buf.push_slice(v, vpos, vlen);
|
|
||||||
self.pos += vlen;
|
|
||||||
}
|
}
|
||||||
fn seek(offset: int, whence: SeekStyle) {
|
fn seek(offset: int, whence: SeekStyle) {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
|
|
|
@ -53,7 +53,7 @@ pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
|
||||||
pure fn get_err<T, U: copy>(res: Result<T, U>) -> U {
|
pure fn get_err<T, U: copy>(res: Result<T, U>) -> U {
|
||||||
match res {
|
match res {
|
||||||
Err(u) => u,
|
Err(u) => u,
|
||||||
Ok(_) => fail ~"get_error called on ok result"
|
Ok(_) => fail ~"get_err called on ok result"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,15 +341,18 @@ fn iter_vec2<S,T,U:copy>(ss: &[S], ts: &[T],
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unwraps a result, assuming it is an `ok(T)`
|
/// Unwraps a result, assuming it is an `ok(T)`
|
||||||
fn unwrap<T, U>(-res: Result<T, U>) -> T {
|
fn unwrap<T, U>(+res: Result<T, U>) -> T {
|
||||||
unsafe {
|
match move res {
|
||||||
let addr = match res {
|
Ok(move t) => t,
|
||||||
Ok(x) => ptr::addr_of(x),
|
Err(_) => fail ~"unwrap called on an err result"
|
||||||
Err(_) => fail ~"error result"
|
}
|
||||||
};
|
}
|
||||||
let liberated_value = unsafe::reinterpret_cast(*addr);
|
|
||||||
unsafe::forget(res);
|
/// Unwraps a result, assuming it is an `err(U)`
|
||||||
return liberated_value;
|
fn unwrap_err<T, U>(+res: Result<T, U>) -> U {
|
||||||
|
match move res {
|
||||||
|
Err(move u) => u,
|
||||||
|
Ok(_) => fail ~"unwrap called on an ok result"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,12 +115,6 @@ export
|
||||||
StrSlice,
|
StrSlice,
|
||||||
UniqueStr;
|
UniqueStr;
|
||||||
|
|
||||||
#[abi = "cdecl"]
|
|
||||||
extern mod rustrt {
|
|
||||||
fn rust_str_push(&s: ~str, ch: u8);
|
|
||||||
fn str_reserve_shared(&ss: ~str, nn: libc::size_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Section: Creating a string
|
Section: Creating a string
|
||||||
*/
|
*/
|
||||||
|
@ -220,14 +214,9 @@ fn push_char(&s: ~str, ch: char) {
|
||||||
*ptr::mut_offset(buf, off + 5u) =
|
*ptr::mut_offset(buf, off + 5u) =
|
||||||
(code & 63u | tag_cont) as u8;
|
(code & 63u | tag_cont) as u8;
|
||||||
}
|
}
|
||||||
*ptr::mut_offset(buf, off + nb) = 0u8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do as_bytes(s) |bytes| {
|
unsafe::set_len(s, new_len);
|
||||||
let mut mut_bytes: ~[u8] = ::unsafe::reinterpret_cast(bytes);
|
|
||||||
vec::unsafe::set_len(mut_bytes, new_len + 1u);
|
|
||||||
::unsafe::forget(mut_bytes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1824,8 +1813,9 @@ pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
|
||||||
* * n - The number of bytes to reserve space for
|
* * n - The number of bytes to reserve space for
|
||||||
*/
|
*/
|
||||||
fn reserve(&s: ~str, n: uint) {
|
fn reserve(&s: ~str, n: uint) {
|
||||||
if capacity(s) < n {
|
unsafe {
|
||||||
rustrt::str_reserve_shared(s, n as size_t);
|
let v: *mut ~[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s));
|
||||||
|
vec::reserve(*v, n + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2003,12 +1993,18 @@ mod unsafe {
|
||||||
|
|
||||||
/// Appends a byte to a string. (Not UTF-8 safe).
|
/// Appends a byte to a string. (Not UTF-8 safe).
|
||||||
unsafe fn push_byte(&s: ~str, b: u8) {
|
unsafe fn push_byte(&s: ~str, b: u8) {
|
||||||
rustrt::rust_str_push(s, b);
|
reserve_at_least(s, s.len() + 1);
|
||||||
|
do as_buf(s) |buf, len| {
|
||||||
|
let buf: *mut u8 = ::unsafe::reinterpret_cast(buf);
|
||||||
|
*ptr::mut_offset(buf, len) = b;
|
||||||
|
}
|
||||||
|
set_len(s, s.len() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
|
/// Appends a vector of bytes to a string. (Not UTF-8 safe).
|
||||||
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
|
unsafe fn push_bytes(&s: ~str, bytes: ~[u8]) {
|
||||||
for vec::each(bytes) |byte| { rustrt::rust_str_push(s, byte); }
|
reserve_at_least(s, s.len() + bytes.len());
|
||||||
|
for vec::each(bytes) |byte| { push_byte(s, byte); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
|
/// Removes the last byte from a string and returns it. (Not UTF-8 safe).
|
||||||
|
|
|
@ -102,9 +102,6 @@ extern mod rustrt {
|
||||||
fn vec_reserve_shared(++t: *sys::TypeDesc,
|
fn vec_reserve_shared(++t: *sys::TypeDesc,
|
||||||
++v: **unsafe::VecRepr,
|
++v: **unsafe::VecRepr,
|
||||||
++n: libc::size_t);
|
++n: libc::size_t);
|
||||||
fn vec_from_buf_shared(++t: *sys::TypeDesc,
|
|
||||||
++ptr: *(),
|
|
||||||
++count: libc::size_t) -> *unsafe::VecRepr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[abi = "rust-intrinsic"]
|
#[abi = "rust-intrinsic"]
|
||||||
|
@ -1727,10 +1724,11 @@ mod unsafe {
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
|
unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
|
||||||
return ::unsafe::reinterpret_cast(
|
let mut dst = ~[];
|
||||||
rustrt::vec_from_buf_shared(sys::get_type_desc::<T>(),
|
reserve(dst, elts);
|
||||||
ptr as *(),
|
set_len(dst, elts);
|
||||||
elts as size_t));
|
as_buf(dst, |p_dst, _len_dst| ptr::memcpy(p_dst, ptr, elts));
|
||||||
|
dst
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1879,7 +1877,7 @@ mod u8 {
|
||||||
pure fn gt(a: &~[u8], b: &~[u8]) -> bool { cmp(a, b) > 0 }
|
pure fn gt(a: &~[u8], b: &~[u8]) -> bool { cmp(a, b) > 0 }
|
||||||
|
|
||||||
/// Byte-vec hash function
|
/// Byte-vec hash function
|
||||||
fn hash(s: &~[u8]) -> uint {
|
pure fn hash(s: &~[u8]) -> uint {
|
||||||
hash::hash_bytes(*s) as uint
|
hash::hash_bytes(*s) as uint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,39 +142,6 @@ vec_reserve_shared(type_desc* ty, rust_vec_box** vp,
|
||||||
reserve_vec_exact(task, vp, n_elts * ty->size);
|
reserve_vec_exact(task, vp, n_elts * ty->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" CDECL void
|
|
||||||
str_reserve_shared(rust_vec_box** sp,
|
|
||||||
size_t n_elts) {
|
|
||||||
rust_task *task = rust_get_current_task();
|
|
||||||
reserve_vec_exact(task, sp, n_elts + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies elements in an unsafe buffer to the given interior vector. The
|
|
||||||
* vector must have size zero.
|
|
||||||
*/
|
|
||||||
extern "C" CDECL rust_vec_box*
|
|
||||||
vec_from_buf_shared(type_desc *ty, void *ptr, size_t count) {
|
|
||||||
rust_task *task = rust_get_current_task();
|
|
||||||
size_t fill = ty->size * count;
|
|
||||||
rust_vec_box* v = (rust_vec_box*)
|
|
||||||
task->kernel->malloc(fill + sizeof(rust_vec_box),
|
|
||||||
"vec_from_buf");
|
|
||||||
v->body.fill = v->body.alloc = fill;
|
|
||||||
memmove(&v->body.data[0], ptr, fill);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" CDECL void
|
|
||||||
rust_str_push(rust_vec_box** sp, uint8_t byte) {
|
|
||||||
rust_task *task = rust_get_current_task();
|
|
||||||
size_t fill = (*sp)->body.fill;
|
|
||||||
reserve_vec(task, sp, fill + 1);
|
|
||||||
(*sp)->body.data[fill-1] = byte;
|
|
||||||
(*sp)->body.data[fill] = 0;
|
|
||||||
(*sp)->body.fill = fill + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" CDECL rust_vec*
|
extern "C" CDECL rust_vec*
|
||||||
rand_seed() {
|
rand_seed() {
|
||||||
size_t size = sizeof(ub4) * RANDSIZ;
|
size_t size = sizeof(ub4) * RANDSIZ;
|
||||||
|
@ -516,8 +483,9 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
|
||||||
out_tm->tm_nsec = nsec;
|
out_tm->tm_nsec = nsec;
|
||||||
|
|
||||||
if (zone != NULL) {
|
if (zone != NULL) {
|
||||||
|
rust_task *task = rust_get_current_task();
|
||||||
size_t size = strlen(zone);
|
size_t size = strlen(zone);
|
||||||
str_reserve_shared(&out_tm->tm_zone, size);
|
reserve_vec_exact(task, &out_tm->tm_zone, size + 1);
|
||||||
memcpy(out_tm->tm_zone->body.data, zone, size);
|
memcpy(out_tm->tm_zone->body.data, zone, size);
|
||||||
out_tm->tm_zone->body.fill = size + 1;
|
out_tm->tm_zone->body.fill = size + 1;
|
||||||
out_tm->tm_zone->body.data[size] = '\0';
|
out_tm->tm_zone->body.data[size] = '\0';
|
||||||
|
|
|
@ -38,7 +38,6 @@ rust_getcwd
|
||||||
rust_get_stdin
|
rust_get_stdin
|
||||||
rust_get_stdout
|
rust_get_stdout
|
||||||
rust_get_stderr
|
rust_get_stderr
|
||||||
rust_str_push
|
|
||||||
rust_list_files
|
rust_list_files
|
||||||
rust_log_console_on
|
rust_log_console_on
|
||||||
rust_log_console_off
|
rust_log_console_off
|
||||||
|
@ -62,8 +61,6 @@ shape_log_str
|
||||||
start_task
|
start_task
|
||||||
vec_reserve_shared_actual
|
vec_reserve_shared_actual
|
||||||
vec_reserve_shared
|
vec_reserve_shared
|
||||||
str_reserve_shared
|
|
||||||
vec_from_buf_shared
|
|
||||||
task_clear_event_reject
|
task_clear_event_reject
|
||||||
task_wait_event
|
task_wait_event
|
||||||
task_signal_event
|
task_signal_event
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue