Skip to content

Various optimizations #5858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
10 changes: 10 additions & 0 deletions src/libcore/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,10 @@ pub mod funcs {
// Omitted: putc, putchar (might be macros).
unsafe fn puts(s: *c_char) -> c_int;
unsafe fn ungetc(c: c_int, stream: *FILE) -> c_int;
#[fast_ffi]
unsafe fn fread(ptr: *mut c_void, size: size_t,
nobj: size_t, stream: *FILE) -> size_t;
#[fast_ffi]
unsafe fn fwrite(ptr: *c_void, size: size_t,
nobj: size_t, stream: *FILE) -> size_t;
unsafe fn fseek(stream: *FILE, offset: c_long,
Expand Down Expand Up @@ -1108,9 +1110,13 @@ pub mod funcs {
-> c_long;
unsafe fn strtoul(s: *c_char, endp: **c_char, base: c_int)
-> c_ulong;
#[fast_ffi]
unsafe fn calloc(nobj: size_t, size: size_t) -> *c_void;
#[fast_ffi]
unsafe fn malloc(size: size_t) -> *c_void;
#[fast_ffi]
unsafe fn realloc(p: *c_void, size: size_t) -> *c_void;
#[fast_ffi]
unsafe fn free(p: *c_void);
unsafe fn abort() -> !;
unsafe fn exit(status: c_int) -> !;
Expand Down Expand Up @@ -1304,6 +1310,7 @@ pub mod funcs {
textmode: c_int) -> c_int;

#[link_name = "_read"]
#[fast_ffi]
unsafe fn read(fd: c_int, buf: *mut c_void, count: c_uint)
-> c_int;

Expand All @@ -1314,6 +1321,7 @@ pub mod funcs {
unsafe fn unlink(c: *c_char) -> c_int;

#[link_name = "_write"]
#[fast_ffi]
unsafe fn write(fd: c_int, buf: *c_void, count: c_uint)
-> c_int;
}
Expand Down Expand Up @@ -1466,6 +1474,7 @@ pub mod funcs {
unsafe fn pathconf(path: *c_char, name: c_int) -> c_long;
unsafe fn pause() -> c_int;
unsafe fn pipe(fds: *mut c_int) -> c_int;
#[fast_ffi]
unsafe fn read(fd: c_int, buf: *mut c_void,
count: size_t) -> ssize_t;
unsafe fn rmdir(path: *c_char) -> c_int;
Expand All @@ -1478,6 +1487,7 @@ pub mod funcs {
unsafe fn tcgetpgrp(fd: c_int) -> pid_t;
unsafe fn ttyname(fd: c_int) -> *c_char;
unsafe fn unlink(c: *c_char) -> c_int;
#[fast_ffi]
unsafe fn write(fd: c_int, buf: *c_void, count: size_t)
-> ssize_t;
}
Expand Down
9 changes: 9 additions & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ pub fn from_bytes_with_null<'a>(vv: &'a [u8]) -> &'a str {
return unsafe { raw::from_bytes_with_null(vv) };
}

pub fn from_bytes_slice<'a>(vector: &'a [u8]) -> &'a str {
unsafe {
assert!(is_utf8(vector));
let (ptr, len): (*u8, uint) = ::cast::transmute(vector);
let string: &'a str = ::cast::transmute((ptr, len + 1));
string
}
}

/// Copy a slice into a new unique str
pub fn from_slice(s: &str) -> ~str {
unsafe { raw::slice_bytes_owned(s, 0, len(s)) }
Expand Down
12 changes: 10 additions & 2 deletions src/libcore/unstable/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ pub mod rustrt {

#[rust_stack]
unsafe fn rust_upcall_free(ptr: *c_char);

#[fast_ffi]
unsafe fn rust_upcall_malloc_noswitch(td: *c_char,
size: uintptr_t)
-> *c_char;

#[fast_ffi]
unsafe fn rust_upcall_free_noswitch(ptr: *c_char);
}
}

Expand Down Expand Up @@ -81,7 +89,7 @@ pub unsafe fn exchange_free(ptr: *c_char) {
#[lang="malloc"]
#[inline(always)]
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
return rustrt::rust_upcall_malloc(td, size);
return rustrt::rust_upcall_malloc_noswitch(td, size);
}

// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
Expand All @@ -90,7 +98,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
#[lang="free"]
#[inline(always)]
pub unsafe fn local_free(ptr: *c_char) {
rustrt::rust_upcall_free(ptr);
rustrt::rust_upcall_free_noswitch(ptr);
}

#[lang="borrow_as_imm"]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ pub mod rustrt {
pub extern {
// These names are terrible. reserve_shared applies
// to ~[] and reserve_shared_actual applies to @[].
#[fast_ffi]
unsafe fn vec_reserve_shared(++t: *sys::TypeDesc,
++v: **raw::VecRepr,
++n: libc::size_t);
#[fast_ffi]
unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
++v: **raw::VecRepr,
++n: libc::size_t);
Expand Down
9 changes: 6 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@ pub enum compile_upto {

// For continuing compilation after a parsed crate has been
// modified
pub fn compile_rest(sess: Session, cfg: ast::crate_cfg,
upto: compile_upto, outputs: Option<@OutputFilenames>,
#[fixed_stack_segment]
pub fn compile_rest(sess: Session,
cfg: ast::crate_cfg,
upto: compile_upto,
outputs: Option<@OutputFilenames>,
curr: Option<@ast::crate>)
-> (@ast::crate, Option<ty::ctxt>) {
-> (@ast::crate, Option<ty::ctxt>) {
let time_passes = sess.time_passes();
let mut crate = curr.get();

Expand Down
Loading