Skip to content

Commit 3525368

Browse files
committed
Use str::repeat
1 parent 3d0e933 commit 3525368

File tree

10 files changed

+24
-41
lines changed

10 files changed

+24
-41
lines changed

src/libcore/tests/num/dec2flt/parse.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::iter;
1211
use core::num::dec2flt::parse::{Decimal, parse_decimal};
1312
use core::num::dec2flt::parse::ParseResult::{Valid, Invalid};
1413

@@ -46,7 +45,7 @@ fn valid() {
4645
assert_eq!(parse_decimal("1.e300"), Valid(Decimal::new(b"1", b"", 300)));
4746
assert_eq!(parse_decimal(".1e300"), Valid(Decimal::new(b"", b"1", 300)));
4847
assert_eq!(parse_decimal("101e-33"), Valid(Decimal::new(b"101", b"", -33)));
49-
let zeros: String = iter::repeat('0').take(25).collect();
48+
let zeros = "0".repeat(25);
5049
let s = format!("1.5e{}", zeros);
5150
assert_eq!(parse_decimal(&s), Valid(Decimal::new(b"1", b"5", 0)));
5251
}

src/librustc/util/common.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::collections::HashMap;
1717
use std::ffi::CString;
1818
use std::fmt::Debug;
1919
use std::hash::{Hash, BuildHasher};
20-
use std::iter::repeat;
2120
use std::panic;
2221
use std::env;
2322
use std::path::Path;
@@ -219,7 +218,7 @@ fn print_time_passes_entry_internal(what: &str, dur: Duration) {
219218
None => "".to_owned(),
220219
};
221220
println!("{}time: {}{}\t{}",
222-
repeat(" ").take(indentation).collect::<String>(),
221+
" ".repeat(indentation),
223222
duration_to_secs_str(dur),
224223
mem_string,
225224
what);

src/librustc_driver/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ use std::error::Error;
9898
use std::ffi::OsString;
9999
use std::fmt::{self, Display};
100100
use std::io::{self, Read, Write};
101-
use std::iter::repeat;
102101
use std::mem;
103102
use std::panic;
104103
use std::path::{PathBuf, Path};
@@ -1253,9 +1252,7 @@ Available lint options:
12531252
.max()
12541253
.unwrap_or(0);
12551254
let padded = |x: &str| {
1256-
let mut s = repeat(" ")
1257-
.take(max_name_len - x.chars().count())
1258-
.collect::<String>();
1255+
let mut s = " ".repeat(max_name_len - x.chars().count());
12591256
s.push_str(x);
12601257
s
12611258
};
@@ -1287,9 +1284,7 @@ Available lint options:
12871284
.unwrap_or(0));
12881285

12891286
let padded = |x: &str| {
1290-
let mut s = repeat(" ")
1291-
.take(max_name_len - x.chars().count())
1292-
.collect::<String>();
1287+
let mut s = " ".repeat(max_name_len - x.chars().count());
12931288
s.push_str(x);
12941289
s
12951290
};

src/librustc_errors/emitter.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,7 @@ impl EmitterWriter {
901901
// | | length of label
902902
// | magic `3`
903903
// `max_line_num_len`
904-
let padding = (0..padding + label.len() + 5)
905-
.map(|_| " ")
906-
.collect::<String>();
904+
let padding = " ".repeat(padding + label.len() + 5);
907905

908906
/// Return whether `style`, or the override if present and the style is `NoStyle`.
909907
fn style_or_override(style: Style, override_style: Option<Style>) -> Style {

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use arena::TypedArena;
3232

3333
use std::cmp::{self, Ordering};
3434
use std::fmt;
35-
use std::iter::{FromIterator, IntoIterator, repeat};
35+
use std::iter::{FromIterator, IntoIterator};
3636

3737
pub fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pattern<'tcx>)
3838
-> &'a Pattern<'tcx>
@@ -115,7 +115,7 @@ impl<'a, 'tcx> fmt::Debug for Matrix<'a, 'tcx> {
115115
}).collect();
116116

117117
let total_width = column_widths.iter().cloned().sum::<usize>() + column_count * 3 + 1;
118-
let br = repeat('+').take(total_width).collect::<String>();
118+
let br = "+".repeat(total_width);
119119
write!(f, "{}\n", br)?;
120120
for row in pretty_printed_matrix {
121121
write!(f, "+")?;

src/librustdoc/html/format.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
//! them in the future to instead emit any format desired.
1717
1818
use std::fmt;
19-
use std::iter::repeat;
2019

2120
use rustc::hir::def_id::DefId;
2221
use rustc_target::spec::abi::Abi;
@@ -235,10 +234,9 @@ impl<'a> fmt::Display for WhereClause<'a> {
235234

236235
if !f.alternate() {
237236
clause.push_str("</span>");
238-
let padding = repeat("&nbsp;").take(indent + 4).collect::<String>();
237+
let padding = "&nbsp;".repeat(indent + 4);
239238
clause = clause.replace("<br>", &format!("<br>{}", padding));
240-
clause.insert_str(0, &repeat("&nbsp;").take(indent.saturating_sub(1))
241-
.collect::<String>());
239+
clause.insert_str(0, &"&nbsp;".repeat(indent.saturating_sub(1)));
242240
if !end_newline {
243241
clause.insert_str(0, "<br>");
244242
}
@@ -409,13 +407,13 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
409407
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
410408
let (fqp, shortty, mut url) = match cache.paths.get(&did) {
411409
Some(&(ref fqp, shortty)) => {
412-
(fqp, shortty, repeat("../").take(loc.len()).collect())
410+
(fqp, shortty, "../".repeat(loc.len()))
413411
}
414412
None => {
415413
let &(ref fqp, shortty) = cache.external_paths.get(&did)?;
416414
(fqp, shortty, match cache.extern_locations[&did.krate] {
417415
(.., render::Remote(ref s)) => s.to_string(),
418-
(.., render::Local) => repeat("../").take(loc.len()).collect(),
416+
(.., render::Local) => "../".repeat(loc.len()),
419417
(.., render::Unknown) => return None,
420418
})
421419
}
@@ -481,7 +479,7 @@ fn primitive_link(f: &mut fmt::Formatter,
481479
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
482480
let len = if len == 0 {0} else {len - 1};
483481
write!(f, "<a class=\"primitive\" href=\"{}primitive.{}.html\">",
484-
repeat("../").take(len).collect::<String>(),
482+
"../".repeat(len),
485483
prim.to_url_str())?;
486484
needs_termination = true;
487485
}
@@ -492,7 +490,7 @@ fn primitive_link(f: &mut fmt::Formatter,
492490
}
493491
(ref cname, _, render::Local) => {
494492
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
495-
Some((cname, repeat("../").take(len).collect::<String>()))
493+
Some((cname, "../".repeat(len)))
496494
}
497495
(.., render::Unknown) => None,
498496
};
@@ -903,15 +901,15 @@ impl<'a> fmt::Display for Method<'a> {
903901
format!("{}", decl.output)
904902
};
905903

906-
let pad = repeat(" ").take(name_len).collect::<String>();
904+
let pad = " ".repeat(name_len);
907905
let plain = format!("{pad}({args}){arrow}",
908906
pad = pad,
909907
args = args_plain,
910908
arrow = arrow_plain);
911909

912910
let output = if plain.len() > 80 {
913-
let full_pad = format!("<br>{}", repeat("&nbsp;").take(indent + 4).collect::<String>());
914-
let close_pad = format!("<br>{}", repeat("&nbsp;").take(indent).collect::<String>());
911+
let full_pad = format!("<br>{}", "&nbsp;".repeat(indent + 4));
912+
let close_pad = format!("<br>{}", "&nbsp;".repeat(indent));
915913
format!("({args}{close}){arrow}",
916914
args = args.replace("<br>", &full_pad),
917915
close = close_pad,

src/librustdoc/html/render.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use std::ffi::OsStr;
4646
use std::fs::{self, File, OpenOptions};
4747
use std::io::prelude::*;
4848
use std::io::{self, BufWriter, BufReader};
49-
use std::iter::repeat;
5049
use std::mem;
5150
use std::path::{PathBuf, Path, Component};
5251
use std::str;
@@ -1712,7 +1711,7 @@ impl Context {
17121711
/// String representation of how to get back to the root path of the 'doc/'
17131712
/// folder in terms of a relative URL.
17141713
fn root_path(&self) -> String {
1715-
repeat("../").take(self.current.len()).collect::<String>()
1714+
"../".repeat(self.current.len())
17161715
}
17171716

17181717
/// Recurse in the directory structure and change the "root path" to make
@@ -2113,8 +2112,7 @@ impl<'a> fmt::Display for Item<'a> {
21132112
let amt = if self.item.is_mod() { cur.len() - 1 } else { cur.len() };
21142113
for (i, component) in cur.iter().enumerate().take(amt) {
21152114
write!(fmt, "<a href='{}index.html'>{}</a>::<wbr>",
2116-
repeat("../").take(cur.len() - i - 1)
2117-
.collect::<String>(),
2115+
"../".repeat(cur.len() - i - 1),
21182116
component)?;
21192117
}
21202118
}

src/libstd/tests/env.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
extern crate rand;
1212

1313
use std::env::*;
14-
use std::iter::repeat;
1514
use std::ffi::{OsString, OsStr};
1615

1716
use rand::Rng;
@@ -72,7 +71,7 @@ fn test_var_big() {
7271
#[cfg_attr(target_os = "emscripten", ignore)]
7372
fn test_env_set_get_huge() {
7473
let n = make_rand_name();
75-
let s = repeat("x").take(10000).collect::<String>();
74+
let s = "x".repeat(10000);
7675
set_var(&n, &s);
7776
eq(var_os(&n), Some(&s));
7877
remove_var(&n);

src/libsyntax/print/pprust.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use tokenstream::{self, TokenStream, TokenTree};
3232

3333
use std::ascii;
3434
use std::io::{self, Write, Read};
35-
use std::iter::{self, Peekable};
35+
use std::iter::Peekable;
3636
use std::vec;
3737

3838
pub enum AnnNode<'a> {
@@ -235,11 +235,11 @@ pub fn token_to_string(tok: &Token) -> String {
235235
token::Integer(c) => c.to_string(),
236236
token::Str_(s) => format!("\"{}\"", s),
237237
token::StrRaw(s, n) => format!("r{delim}\"{string}\"{delim}",
238-
delim=repeat("#", n as usize),
238+
delim="#".repeat(n as usize),
239239
string=s),
240240
token::ByteStr(v) => format!("b\"{}\"", v),
241241
token::ByteStrRaw(s, n) => format!("br{delim}\"{string}\"{delim}",
242-
delim=repeat("#", n as usize),
242+
delim="#".repeat(n as usize),
243243
string=s),
244244
};
245245

@@ -661,7 +661,7 @@ pub trait PrintState<'a> {
661661
}
662662
ast::StrStyle::Raw(n) => {
663663
(format!("r{delim}\"{string}\"{delim}",
664-
delim=repeat("#", n as usize),
664+
delim="#".repeat(n as usize),
665665
string=st))
666666
}
667667
};
@@ -3180,8 +3180,6 @@ impl<'a> State<'a> {
31803180
}
31813181
}
31823182

3183-
fn repeat(s: &str, n: usize) -> String { iter::repeat(s).take(n).collect() }
3184-
31853183
#[cfg(test)]
31863184
mod tests {
31873185
use super::*;

src/libtest/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ use std::fmt;
6666
use std::fs::File;
6767
use std::io::prelude::*;
6868
use std::io;
69-
use std::iter::repeat;
7069
use std::path::PathBuf;
7170
use std::process::Termination;
7271
use std::sync::mpsc::{channel, Sender};
@@ -145,7 +144,7 @@ impl TestDesc {
145144
fn padded_name(&self, column_count: usize, align: NamePadding) -> String {
146145
let mut name = String::from(self.name.as_slice());
147146
let fill = column_count.saturating_sub(name.len());
148-
let pad = repeat(" ").take(fill).collect::<String>();
147+
let pad = " ".repeat(fill);
149148
match align {
150149
PadNone => name,
151150
PadOnRight => {

0 commit comments

Comments
 (0)