diff --git a/src/libcore/unstable/lang.rs b/src/libcore/unstable/lang.rs index 554083fcdb53ba9142e7a3b6bfac743cf762d9f4..ff96029bc0e31b887a2f256c27f88c802dd8d0bc 100644 --- a/src/libcore/unstable/lang.rs +++ b/src/libcore/unstable/lang.rs @@ -64,6 +64,7 @@ pub unsafe fn fail_borrowed() { // FIXME #4942: Make these signatures agree with exchange_alloc's signatures #[lang="exchange_malloc"] +#[inline(always)] pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { transmute(exchange_alloc::malloc(transmute(td), transmute(size))) } @@ -72,11 +73,13 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char { // inside a landing pad may corrupt the state of the exception handler. If a // problem occurs, call exit instead. #[lang="exchange_free"] +#[inline(always)] pub unsafe fn exchange_free(ptr: *c_char) { exchange_alloc::free(transmute(ptr)) } #[lang="malloc"] +#[inline(always)] pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char { return rustrt::rust_upcall_malloc(td, size); } @@ -85,6 +88,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char { // inside a landing pad may corrupt the state of the exception handler. If a // problem occurs, call exit instead. #[lang="free"] +#[inline(always)] pub unsafe fn local_free(ptr: *c_char) { rustrt::rust_upcall_free(ptr); } @@ -117,6 +121,7 @@ pub unsafe fn check_not_borrowed(a: *u8) { } #[lang="strdup_uniq"] +#[inline(always)] pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str { str::raw::from_buf_len(ptr, len) } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 5855add7975ca063338f467a2fc15e2506a92316..331bede5b7af37775d8db77ee9900722c8880224 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -411,13 +411,13 @@ fn read_tup_elt(&self, idx: uint, f: &fn() -> T) -> T { } #[cfg(stage0)] - fn read_option(&self, f: &fn() -> T) -> Option { + fn read_option(&self, f: &fn(bool) -> T) -> T { debug!("read_option()"); do self.read_enum("Option") || { do self.read_enum_variant |idx| { match idx { - 0 => None, - 1 => Some(f()), + 0 => f(false), + 1 => f(true), _ => fail!(), } } @@ -427,13 +427,13 @@ fn read_option(&self, f: &fn() -> T) -> Option { #[cfg(stage1)] #[cfg(stage2)] #[cfg(stage3)] - fn read_option(&self, f: &fn() -> T) -> Option { + fn read_option(&self, f: &fn(bool) -> T) -> T { debug!("read_option()"); do self.read_enum("Option") || { do self.read_enum_variant(["None", "Some"]) |idx| { match idx { - 0 => None, - 1 => Some(f()), + 0 => f(false), + 1 => f(true), _ => fail!(), } } diff --git a/src/libstd/json.rs b/src/libstd/json.rs index c48b210dca219c3023eb4a6eebdcd049037f1394..4b0e313330d24b22e9649c437c6124263fec21bb 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -980,10 +980,10 @@ fn read_tup_elt(&self, idx: uint, f: &fn() -> T) -> T { } } - fn read_option(&self, f: &fn() -> T) -> Option { + fn read_option(&self, f: &fn(bool) -> T) -> T { match *self.peek() { - Null => { self.pop(); None } - _ => Some(f()), + Null => { self.pop(); f(false) } + _ => f(true), } } } diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index 02f4a934874325bc73ab582ecc2e4fdb624a4b53..3c9ad0d77d1e01a64cc0f88c7ff4dfffc9a5c72d 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -118,7 +118,7 @@ pub trait Decoder { fn read_tup_elt(&self, idx: uint, f: &fn() -> T) -> T; // Specialized types: - fn read_option(&self, f: &fn() -> T) -> Option; + fn read_option(&self, f: &fn(bool) -> T) -> T; } pub trait Encodable { @@ -395,7 +395,13 @@ fn encode(&self, s: &S) { impl> Decodable for Option { fn decode(d: &D) -> Option { - d.read_option(|| Decodable::decode(d)) + do d.read_option |b| { + if b { + Some(Decodable::decode(d)) + } else { + None + } + } } }