Skip to content

Commit 814e2d3

Browse files
committed
---
yaml --- r: 57183 b: refs/heads/try c: a74aca5 h: refs/heads/master i: 57181: e347519 57179: 31ef5c1 57175: 9e1dbdd 57167: 7029a69 57151: 1034935 v: v3
1 parent d3ef547 commit 814e2d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1123
-864
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: 11d04d452fa8fd8adde10f8de902bfffc59ab704
5+
refs/heads/try: a74aca54826e19f8f125571cb8d72f6addb65a4c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/doc/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ An example of `use` declarations:
802802

803803
~~~~
804804
use core::float::sin;
805-
use core::str::{slice, to_upper};
805+
use core::str::{slice, contains};
806806
use core::option::Some;
807807
808808
fn main() {
@@ -813,8 +813,8 @@ fn main() {
813813
info!(Some(1.0));
814814
815815
// Equivalent to
816-
// 'info!(core::str::to_upper(core::str::slice("foo", 0, 1)));'
817-
info!(to_upper(slice("foo", 0, 1)));
816+
// 'info!(core::str::contains(core::str::slice("foo", 0, 1), "oo"));'
817+
info!(contains(slice("foo", 0, 1), "oo"));
818818
}
819819
~~~~
820820

branches/try/src/compiletest/errors.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
5050
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
5151
let start_kind = idx;
5252
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
53-
let kind = str::to_lower(str::slice(line, start_kind, idx).to_owned());
53+
54+
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
55+
// to_ascii_consume and to_str_consume to not do a unnecessary copy.
56+
let kind = str::slice(line, start_kind, idx);
57+
let kind = kind.to_ascii().to_lower().to_str_ascii();
5458

5559
// Extract msg:
5660
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }

branches/try/src/libcore/char.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ pub fn is_alphanumeric(c: char) -> bool {
100100
unicode::general_category::No(c);
101101
}
102102

103-
/// Indicates whether the character is an ASCII character
104-
#[inline(always)]
105-
pub fn is_ascii(c: char) -> bool {
106-
c - ('\x7F' & c) == '\x00'
107-
}
108-
109103
/// Indicates whether the character is numeric (Nd, Nl, or No)
110104
#[inline(always)]
111105
pub fn is_digit(c: char) -> bool {
@@ -116,7 +110,7 @@ pub fn is_digit(c: char) -> bool {
116110

117111
/**
118112
* Checks if a character parses as a numeric digit in the given radix.
119-
* Compared to `is_digit()`, this function only recognizes the ascii
113+
* Compared to `is_digit()`, this function only recognizes the
120114
* characters `0-9`, `a-z` and `A-Z`.
121115
*
122116
* Returns `true` if `c` is a valid digit under `radix`, and `false`
@@ -163,7 +157,7 @@ pub fn to_digit(c: char, radix: uint) -> Option<uint> {
163157
}
164158

165159
/**
166-
* Converts a number to the ascii character representing it.
160+
* Converts a number to the character representing it.
167161
*
168162
* Returns `Some(char)` if `num` represents one digit under `radix`,
169163
* using one character of `0-9` or `a-z`, or `None` if it doesn't.
@@ -316,12 +310,6 @@ fn test_to_digit() {
316310
assert!(to_digit('$', 36u).is_none());
317311
}
318312
319-
#[test]
320-
fn test_is_ascii() {
321-
assert!(str::all(~"banana", is_ascii));
322-
assert!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
323-
}
324-
325313
#[test]
326314
fn test_is_digit() {
327315
assert!(is_digit('2'));

branches/try/src/libcore/core.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
105105
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
106106
pub use iter::{ExtendedMutableIter};
107107

108-
pub use num::{Num, NumCast};
108+
pub use num::{Num, Signed, Unsigned, Natural, NumCast};
109109
pub use ptr::Ptr;
110110
pub use to_str::ToStr;
111111
pub use clone::Clone;

branches/try/src/libcore/flate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
8585
#[test]
8686
#[allow(non_implicitly_copyable_typarams)]
8787
fn test_flate_round_trip() {
88-
let r = rand::Rng();
88+
let r = rand::rng();
8989
let mut words = ~[];
9090
for 20.times {
9191
words.push(r.gen_bytes(r.gen_uint_range(1, 10)));

branches/try/src/libcore/hashmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn resize_at(capacity: uint) -> uint {
5656
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
5757
initial_capacity: uint) -> HashMap<K, V> {
5858
let r = rand::task_rng();
59-
linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(),
59+
linear_map_with_capacity_and_keys(r.gen(), r.gen(),
6060
initial_capacity)
6161
}
6262

branches/try/src/libcore/iterator.rs

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,6 @@ impl<A, T: Iterator<A>> Iterator<A> for TakeIterator<T> {
312312
}
313313
}
314314

315-
pub struct ScanIterator<'self, A, B, T, St> {
316-
priv iter: T,
317-
priv f: &'self fn(&mut St, A) -> Option<B>,
318-
state: St
319-
}
320-
321-
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
322-
#[inline]
323-
fn next(&mut self) -> Option<B> {
324-
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
325-
}
326-
}
327-
328315
pub struct UnfoldrIterator<'self, A, St> {
329316
priv f: &'self fn(&mut St) -> Option<A>,
330317
state: St
@@ -348,25 +335,16 @@ impl<'self, A, St> Iterator<A> for UnfoldrIterator<'self, A, St> {
348335
}
349336
}
350337

351-
/// An infinite iterator starting at `start` and advancing by `step` with each iteration
352-
pub struct Counter<A> {
353-
state: A,
354-
step: A
355-
}
356-
357-
pub impl<A> Counter<A> {
358-
#[inline(always)]
359-
fn new(start: A, step: A) -> Counter<A> {
360-
Counter{state: start, step: step}
361-
}
338+
pub struct ScanIterator<'self, A, B, T, St> {
339+
priv iter: T,
340+
priv f: &'self fn(&mut St, A) -> Option<B>,
341+
state: St
362342
}
363343

364-
impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
365-
#[inline(always)]
366-
fn next(&mut self) -> Option<A> {
367-
let result = self.state.clone();
368-
self.state = self.state.add(&self.step); // FIXME: #6050
369-
Some(result)
344+
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
345+
#[inline]
346+
fn next(&mut self) -> Option<B> {
347+
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
370348
}
371349
}
372350

@@ -375,13 +353,6 @@ mod tests {
375353
use super::*;
376354
use prelude::*;
377355

378-
#[test]
379-
fn test_counter_to_vec() {
380-
let mut it = Counter::new(0, 5).take(10);
381-
let xs = iter::iter_to_vec(|f| it.advance(f));
382-
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
383-
}
384-
385356
#[test]
386357
fn test_iterator_chain() {
387358
let xs = [0u, 1, 2, 3, 4, 5];

branches/try/src/libcore/num/f32.rs

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! Operations and constants for `f32`
1212
1313
use num::strconv;
14+
use num::Signed;
1415
use num;
1516
use option::Option;
1617
use from_str;
@@ -163,38 +164,6 @@ pub fn gt(x: f32, y: f32) -> bool { return x > y; }
163164
// FIXME (#1999): replace the predicates below with llvm intrinsics or
164165
// calls to the libmath macros in the rust runtime for performance.
165166

166-
/// Returns true if `x` is a positive number, including +0.0f320 and +Infinity
167-
#[inline(always)]
168-
pub fn is_positive(x: f32) -> bool {
169-
x > 0.0f32 || (1.0f32/x) == infinity
170-
}
171-
172-
/// Returns true if `x` is a negative number, including -0.0f320 and -Infinity
173-
#[inline(always)]
174-
pub fn is_negative(x: f32) -> bool {
175-
x < 0.0f32 || (1.0f32/x) == neg_infinity
176-
}
177-
178-
/**
179-
* Returns true if `x` is a negative number, including -0.0f320 and -Infinity
180-
*
181-
* This is the same as `f32::is_negative`.
182-
*/
183-
#[inline(always)]
184-
pub fn is_nonpositive(x: f32) -> bool {
185-
return x < 0.0f32 || (1.0f32/x) == neg_infinity;
186-
}
187-
188-
/**
189-
* Returns true if `x` is a positive number, including +0.0f320 and +Infinity
190-
*
191-
* This is the same as `f32::is_positive`.)
192-
*/
193-
#[inline(always)]
194-
pub fn is_nonnegative(x: f32) -> bool {
195-
return x > 0.0f32 || (1.0f32/x) == infinity;
196-
}
197-
198167
/// Returns true if `x` is a zero number (positive or negative zero)
199168
#[inline(always)]
200169
pub fn is_zero(x: f32) -> bool {
@@ -259,11 +228,6 @@ pub mod consts {
259228
pub static ln_10: f32 = 2.30258509299404568401799145468436421_f32;
260229
}
261230

262-
#[inline(always)]
263-
pub fn signbit(x: f32) -> int {
264-
if is_negative(x) { return 1; } else { return 0; }
265-
}
266-
267231
#[inline(always)]
268232
pub fn logarithm(n: f32, b: f32) -> f32 {
269233
return log2(n) / log2(b);
@@ -351,15 +315,41 @@ impl Neg<f32> for f32 {
351315
fn neg(&self) -> f32 { -*self }
352316
}
353317

318+
impl Signed for f32 {
319+
/// Computes the absolute value. Returns `NaN` if the number is `NaN`.
320+
#[inline(always)]
321+
fn abs(&self) -> f32 { abs(*self) }
322+
323+
/**
324+
* # Returns
325+
*
326+
* - `1.0` if the number is positive, `+0.0` or `infinity`
327+
* - `-1.0` if the number is negative, `-0.0` or `neg_infinity`
328+
* - `NaN` if the number is `NaN`
329+
*/
330+
#[inline(always)]
331+
fn signum(&self) -> f32 {
332+
if is_NaN(*self) { NaN } else { copysign(1.0, *self) }
333+
}
334+
335+
/// Returns `true` if the number is positive, including `+0.0` and `infinity`
336+
#[inline(always)]
337+
fn is_positive(&self) -> bool { *self > 0.0 || (1.0 / *self) == infinity }
338+
339+
/// Returns `true` if the number is negative, including `-0.0` and `neg_infinity`
340+
#[inline(always)]
341+
fn is_negative(&self) -> bool { *self < 0.0 || (1.0 / *self) == neg_infinity }
342+
}
343+
354344
impl num::Round for f32 {
355345
#[inline(always)]
356346
fn round(&self, mode: num::RoundMode) -> f32 {
357347
match mode {
358348
num::RoundDown => floor(*self),
359349
num::RoundUp => ceil(*self),
360-
num::RoundToZero if is_negative(*self) => ceil(*self),
350+
num::RoundToZero if self.is_negative() => ceil(*self),
361351
num::RoundToZero => floor(*self),
362-
num::RoundFromZero if is_negative(*self) => floor(*self),
352+
num::RoundFromZero if self.is_negative() => floor(*self),
363353
num::RoundFromZero => ceil(*self)
364354
}
365355
}
@@ -370,7 +360,7 @@ impl num::Round for f32 {
370360
fn ceil(&self) -> f32 { ceil(*self) }
371361
#[inline(always)]
372362
fn fract(&self) -> f32 {
373-
if is_negative(*self) {
363+
if self.is_negative() {
374364
(*self) - ceil(*self)
375365
} else {
376366
(*self) - floor(*self)
@@ -595,6 +585,50 @@ impl num::FromStrRadix for f32 {
595585
}
596586
}
597587

588+
#[cfg(test)]
589+
mod tests {
590+
use f32::*;
591+
592+
#[test]
593+
pub fn test_signed() {
594+
assert_eq!(infinity.abs(), infinity);
595+
assert_eq!(1f32.abs(), 1f32);
596+
assert_eq!(0f32.abs(), 0f32);
597+
assert_eq!((-0f32).abs(), 0f32);
598+
assert_eq!((-1f32).abs(), 1f32);
599+
assert_eq!(neg_infinity.abs(), infinity);
600+
assert_eq!((1f32/neg_infinity).abs(), 0f32);
601+
assert!(is_NaN(NaN.abs()));
602+
603+
assert_eq!(infinity.signum(), 1f32);
604+
assert_eq!(1f32.signum(), 1f32);
605+
assert_eq!(0f32.signum(), 1f32);
606+
assert_eq!((-0f32).signum(), -1f32);
607+
assert_eq!((-1f32).signum(), -1f32);
608+
assert_eq!(neg_infinity.signum(), -1f32);
609+
assert_eq!((1f32/neg_infinity).signum(), -1f32);
610+
assert!(is_NaN(NaN.signum()));
611+
612+
assert!(infinity.is_positive());
613+
assert!(1f32.is_positive());
614+
assert!(0f32.is_positive());
615+
assert!(!(-0f32).is_positive());
616+
assert!(!(-1f32).is_positive());
617+
assert!(!neg_infinity.is_positive());
618+
assert!(!(1f32/neg_infinity).is_positive());
619+
assert!(!NaN.is_positive());
620+
621+
assert!(!infinity.is_negative());
622+
assert!(!1f32.is_negative());
623+
assert!(!0f32.is_negative());
624+
assert!((-0f32).is_negative());
625+
assert!((-1f32).is_negative());
626+
assert!(neg_infinity.is_negative());
627+
assert!((1f32/neg_infinity).is_negative());
628+
assert!(!NaN.is_negative());
629+
}
630+
}
631+
598632
//
599633
// Local Variables:
600634
// mode: rust

0 commit comments

Comments
 (0)