Skip to content

Commit 3d588c5

Browse files
committed
auto merge of #5555 : Kimundi/rust/str-dealloc-3, r=catamorphism
- Most functions that used to return `~[~str]` for a list of substrings got turned into iterators over `&str` slices - Some cleanup of apis, docs and code layout
2 parents 3f7c74d + de468c8 commit 3d588c5

File tree

25 files changed

+461
-409
lines changed

25 files changed

+461
-409
lines changed

src/compiletest/header.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ fn parse_check_line(line: ~str) -> Option<~str> {
142142
fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
143143
do parse_name_value_directive(line, ~"exec-env").map |nv| {
144144
// nv is either FOO or FOO=BAR
145-
let strs = str::splitn_char(*nv, '=', 1u);
145+
let mut strs = ~[];
146+
for str::each_splitn_char(*nv, '=', 1u) |s| { strs.push(s.to_owned()); }
146147
match strs.len() {
147148
1u => (strs[0], ~""),
148149
2u => (strs[0], strs[1]),

src/compiletest/runtest.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
267267
// check if each line in props.check_lines appears in the
268268
// output (in order)
269269
let mut i = 0u;
270-
for str::lines_each(ProcRes.stdout) |line| {
270+
for str::each_line(ProcRes.stdout) |line| {
271271
if props.check_lines[i].trim() == line.trim() {
272272
i += 1u;
273273
}
@@ -297,7 +297,7 @@ fn check_error_patterns(props: TestProps,
297297
let mut next_err_idx = 0u;
298298
let mut next_err_pat = props.error_patterns[next_err_idx];
299299
let mut done = false;
300-
for str::lines_each(ProcRes.stderr) |line| {
300+
for str::each_line(ProcRes.stderr) |line| {
301301
if str::contains(line, next_err_pat) {
302302
debug!("found error pattern %s", next_err_pat);
303303
next_err_idx += 1u;
@@ -347,7 +347,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
347347
// filename:line1:col1: line2:col2: *warning:* msg
348348
// where line1:col1: is the starting point, line2:col2:
349349
// is the ending point, and * represents ANSI color codes.
350-
for str::lines_each(ProcRes.stderr) |line| {
350+
for str::each_line(ProcRes.stderr) |line| {
351351
let mut was_expected = false;
352352
for vec::eachi(expected_errors) |i, ee| {
353353
if !found_flags[i] {
@@ -596,8 +596,12 @@ fn split_maybe_args(argstr: Option<~str>) -> ~[~str] {
596596
}
597597

598598
match argstr {
599-
Some(s) => rm_whitespace(str::split_char(s, ' ')),
600-
None => ~[]
599+
Some(s) => {
600+
let mut ss = ~[];
601+
for str::each_split_char(s, ' ') |s| { ss.push(s.to_owned()) }
602+
rm_whitespace(ss)
603+
}
604+
None => ~[]
601605
}
602606
}
603607

src/libcore/num/strconv.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ impl_NumStrConv_Integer!(u16)
130130
impl_NumStrConv_Integer!(u32)
131131
impl_NumStrConv_Integer!(u64)
132132

133+
134+
// Special value strings as [u8] consts.
135+
static inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8];
136+
static positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8, 'n' as u8, 'f' as u8];
137+
static negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8, 'n' as u8, 'f' as u8];
138+
static nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8];
139+
133140
/**
134141
* Converts a number to its string representation as a byte vector.
135142
* This is meant to be a common base implementation for all numeric string
@@ -479,15 +486,15 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
479486
}
480487

481488
if special {
482-
if buf == str::inf_buf || buf == str::positive_inf_buf {
489+
if buf == inf_buf || buf == positive_inf_buf {
483490
return NumStrConv::inf();
484-
} else if buf == str::negative_inf_buf {
491+
} else if buf == negative_inf_buf {
485492
if negative {
486493
return NumStrConv::neg_inf();
487494
} else {
488495
return None;
489496
}
490-
} else if buf == str::nan_buf {
497+
} else if buf == nan_buf {
491498
return NumStrConv::NaN();
492499
}
493500
}

src/libcore/os.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ pub fn env() -> ~[(~str,~str)] {
218218
fn env_convert(input: ~[~str]) -> ~[(~str, ~str)] {
219219
let mut pairs = ~[];
220220
for input.each |p| {
221-
let vs = str::splitn_char(*p, '=', 1);
221+
let mut vs = ~[];
222+
for str::each_splitn_char(*p, '=', 1) |s| { vs.push(s.to_owned()) }
222223
debug!("splitting: len: %u",
223224
vs.len());
224225
fail_unless!(vs.len() == 2);

src/libcore/path.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ impl ToStr for PosixPath {
381381
impl GenericPath for PosixPath {
382382

383383
fn from_str(s: &str) -> PosixPath {
384-
let mut components = str::split_nonempty(s, |c| c == '/');
384+
let mut components = ~[];
385+
for str::each_split_nonempty(s, |c| c == '/') |s| { components.push(s.to_owned()) }
385386
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
386387
return PosixPath { is_absolute: is_absolute,
387388
components: components }
@@ -504,9 +505,10 @@ impl GenericPath for PosixPath {
504505
fn push_many(&self, cs: &[~str]) -> PosixPath {
505506
let mut v = copy self.components;
506507
for cs.each |e| {
507-
let mut ss = str::split_nonempty(
508-
*e,
509-
|c| windows::is_sep(c as u8));
508+
let mut ss = ~[];
509+
for str::each_split_nonempty(*e, |c| windows::is_sep(c as u8)) |s| {
510+
ss.push(s.to_owned())
511+
}
510512
unsafe { v.push_all_move(ss); }
511513
}
512514
PosixPath { is_absolute: self.is_absolute,
@@ -515,7 +517,10 @@ impl GenericPath for PosixPath {
515517

516518
fn push(&self, s: &str) -> PosixPath {
517519
let mut v = copy self.components;
518-
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
520+
let mut ss = ~[];
521+
for str::each_split_nonempty(s, |c| windows::is_sep(c as u8)) |s| {
522+
ss.push(s.to_owned())
523+
}
519524
unsafe { v.push_all_move(ss); }
520525
PosixPath { components: v, ..copy *self }
521526
}
@@ -590,8 +595,10 @@ impl GenericPath for WindowsPath {
590595
}
591596
}
592597

593-
let mut components =
594-
str::split_nonempty(rest, |c| windows::is_sep(c as u8));
598+
let mut components = ~[];
599+
for str::each_split_nonempty(rest, |c| windows::is_sep(c as u8)) |s| {
600+
components.push(s.to_owned())
601+
}
595602
let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0]));
596603
return WindowsPath { host: host,
597604
device: device,
@@ -759,9 +766,10 @@ impl GenericPath for WindowsPath {
759766
fn push_many(&self, cs: &[~str]) -> WindowsPath {
760767
let mut v = copy self.components;
761768
for cs.each |e| {
762-
let mut ss = str::split_nonempty(
763-
*e,
764-
|c| windows::is_sep(c as u8));
769+
let mut ss = ~[];
770+
for str::each_split_nonempty(*e, |c| windows::is_sep(c as u8)) |s| {
771+
ss.push(s.to_owned())
772+
}
765773
unsafe { v.push_all_move(ss); }
766774
}
767775
// tedious, but as-is, we can't use ..self
@@ -775,7 +783,10 @@ impl GenericPath for WindowsPath {
775783

776784
fn push(&self, s: &str) -> WindowsPath {
777785
let mut v = copy self.components;
778-
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
786+
let mut ss = ~[];
787+
for str::each_split_nonempty(s, |c| windows::is_sep(c as u8)) |s| {
788+
ss.push(s.to_owned())
789+
}
779790
unsafe { v.push_all_move(ss); }
780791
return WindowsPath { components: v, ..copy *self }
781792
}

src/libcore/rand.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ impl RngUtil for @Rng {
327327
*/
328328
fn gen_char_from(&self, chars: &str) -> char {
329329
fail_unless!(!chars.is_empty());
330-
self.choose(str::chars(chars))
330+
let mut cs = ~[];
331+
for str::each_char(chars) |c| { cs.push(c) }
332+
self.choose(cs)
331333
}
332334

333335
/// Return a random bool

0 commit comments

Comments
 (0)