Auto merge of #52646 - ljedrz:single_char_pattern, r=michaelwoerister
Change single char str patterns to chars A `char` is faster.
This commit is contained in:
commit
a2af8667b1
@ -40,7 +40,7 @@ pub fn accepts_all(&self) -> bool {
|
||||
/// Tests whether `node` meets the filter, returning true if so.
|
||||
pub fn test(&self, node: &DepNode) -> bool {
|
||||
let debug_str = format!("{:?}", node);
|
||||
self.text.split("&")
|
||||
self.text.split('&')
|
||||
.map(|s| s.trim())
|
||||
.all(|f| debug_str.contains(f))
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ fn annotate<F>(&mut self, id: NodeId, attrs: &[Attribute],
|
||||
&attr::Stable {since: stab_since}) = (&stab.rustc_depr, &stab.level) {
|
||||
// Explicit version of iter::order::lt to handle parse errors properly
|
||||
for (dep_v, stab_v) in
|
||||
dep_since.as_str().split(".").zip(stab_since.as_str().split(".")) {
|
||||
dep_since.as_str().split('.').zip(stab_since.as_str().split('.')) {
|
||||
if let (Ok(dep_v), Ok(stab_v)) = (dep_v.parse::<u64>(), stab_v.parse()) {
|
||||
match dep_v.cmp(&stab_v) {
|
||||
Ordering::Less => {
|
||||
|
@ -117,8 +117,8 @@ pub fn dump_enabled<'a, 'gcx, 'tcx>(
|
||||
// see notes on #41697 below
|
||||
tcx.item_path_str(source.def_id)
|
||||
});
|
||||
filters.split("|").any(|or_filter| {
|
||||
or_filter.split("&").all(|and_filter| {
|
||||
filters.split('|').any(|or_filter| {
|
||||
or_filter.split('&').all(|and_filter| {
|
||||
and_filter == "all" || pass_name.contains(and_filter) || node_path.contains(and_filter)
|
||||
})
|
||||
})
|
||||
@ -388,7 +388,7 @@ struct ExtraComments<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
|
||||
|
||||
impl<'cx, 'gcx, 'tcx> ExtraComments<'cx, 'gcx, 'tcx> {
|
||||
fn push(&mut self, lines: &str) {
|
||||
for line in lines.split("\n") {
|
||||
for line in lines.split('\n') {
|
||||
self.comments.push(line.to_string());
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ pub fn parse(target: &Target) -> Result<TargetDataLayout, String> {
|
||||
|
||||
let mut dl = TargetDataLayout::default();
|
||||
let mut i128_align_src = 64;
|
||||
for spec in target.data_layout.split("-") {
|
||||
match &spec.split(":").collect::<Vec<_>>()[..] {
|
||||
for spec in target.data_layout.split('-') {
|
||||
match &spec.split(':').collect::<Vec<_>>()[..] {
|
||||
&["e"] => dl.endian = Endian::Little,
|
||||
&["E"] => dl.endian = Endian::Big,
|
||||
&["a", ref a..] => dl.aggregate_align = align(a, "a")?,
|
||||
|
@ -41,12 +41,12 @@ fn next(&mut self) -> Option<Self::Item> {
|
||||
pub fn lookup_host(host: &str) -> Result<LookupHost> {
|
||||
let mut ip_string = String::new();
|
||||
File::open("/etc/net/ip")?.read_to_string(&mut ip_string)?;
|
||||
let ip: Vec<u8> = ip_string.trim().split(".").map(|part| part.parse::<u8>()
|
||||
let ip: Vec<u8> = ip_string.trim().split('.').map(|part| part.parse::<u8>()
|
||||
.unwrap_or(0)).collect();
|
||||
|
||||
let mut dns_string = String::new();
|
||||
File::open("/etc/net/dns")?.read_to_string(&mut dns_string)?;
|
||||
let dns: Vec<u8> = dns_string.trim().split(".").map(|part| part.parse::<u8>()
|
||||
let dns: Vec<u8> = dns_string.trim().split('.').map(|part| part.parse::<u8>()
|
||||
.unwrap_or(0)).collect();
|
||||
|
||||
if ip.len() == 4 && dns.len() == 4 {
|
||||
|
@ -564,7 +564,7 @@ fn gnu_get_libc_version() -> *const libc::c_char
|
||||
// ignoring any extra dot-separated parts. Otherwise return None.
|
||||
#[cfg(target_env = "gnu")]
|
||||
fn parse_glibc_version(version: &str) -> Option<(usize, usize)> {
|
||||
let mut parsed_ints = version.split(".").map(str::parse::<usize>).fuse();
|
||||
let mut parsed_ints = version.split('.').map(str::parse::<usize>).fuse();
|
||||
match (parsed_ints.next(), parsed_ints.next()) {
|
||||
(Some(Ok(major)), Some(Ok(minor))) => Some((major, minor)),
|
||||
_ => None
|
||||
|
@ -165,7 +165,7 @@ pub fn id_str(&self) -> String {
|
||||
impl<'a> CrateVersion<'a> {
|
||||
/// Returns the struct and whether or not the dep is in-tree
|
||||
pub fn from_str(s: &'a str) -> (Self, bool) {
|
||||
let mut parts = s.split(" ");
|
||||
let mut parts = s.split(' ');
|
||||
let name = parts.next().unwrap();
|
||||
let version = parts.next().unwrap();
|
||||
let path = parts.next().unwrap();
|
||||
|
@ -257,7 +257,7 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features {
|
||||
None
|
||||
} else {
|
||||
next_feature_is_rustc_internal = false;
|
||||
let s = issue_str.split("(").nth(1).unwrap().split(")").nth(0).unwrap();
|
||||
let s = issue_str.split('(').nth(1).unwrap().split(')').nth(0).unwrap();
|
||||
Some(s.parse().unwrap())
|
||||
};
|
||||
Some((name.to_owned(),
|
||||
|
@ -131,7 +131,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||
let skip_length = contents.contains("ignore-tidy-linelength");
|
||||
let skip_end_whitespace = contents.contains("ignore-tidy-end-whitespace");
|
||||
let mut trailing_new_lines = 0;
|
||||
for (i, line) in contents.split("\n").enumerate() {
|
||||
for (i, line) in contents.split('\n').enumerate() {
|
||||
let mut err = |msg: &str| {
|
||||
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user