Skip to content

Commit

Permalink
Simplify empty check, relace length validation to is_empty()
Browse files Browse the repository at this point in the history
  • Loading branch information
chinsyo committed Oct 8, 2024
1 parent 40a6ced commit ac323bc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions leaf/src/app/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,15 @@ impl Router {
for rr in routing_rules.iter_mut() {
let mut cond_and = ConditionAnd::new();

if rr.domains.len() > 0 {
if !rr.domains.is_empty() {
cond_and.add(Box::new(DomainMatcher::new(&mut rr.domains)));
}

if rr.ip_cidrs.len() > 0 {
if !rr.ip_cidrs.is_empty() {
cond_and.add(Box::new(IpCidrMatcher::new(&mut rr.ip_cidrs)));
}

if rr.mmdbs.len() > 0 {
if !rr.mmdbs.is_empty() {
for mmdb in rr.mmdbs.iter() {
let reader = match mmdb_readers.get(&mmdb.file) {
Some(r) => r.clone(),
Expand All @@ -455,15 +455,15 @@ impl Router {
}
}

if rr.port_ranges.len() > 0 {
if !rr.port_ranges.is_empty() {
cond_and.add(Box::new(PortMatcher::new(&rr.port_ranges)));
}

if rr.networks.len() > 0 {
if !rr.networks.is_empty() {
cond_and.add(Box::new(NetworkMatcher::new(&mut rr.networks)));
}

if rr.inbound_tags.len() > 0 {
if !rr.inbound_tags.is_empty() {
cond_and.add(Box::new(InboundTagMatcher::new(&mut rr.inbound_tags)));
}

Expand Down
4 changes: 2 additions & 2 deletions leaf/src/common/sniff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
let bytes_str = String::from_utf8_lossy(buf);
let parts: Vec<&str> = bytes_str.split("\r\n").collect();

if parts.len() == 0 {
if parts.is_empty() {
return SniffResult::NotMatch;
}

Expand All @@ -84,7 +84,7 @@ where
}

for (idx, &el) in parts.iter().enumerate() {
if idx == 0 || el == "" {
if idx == 0 || el.is_empty() {
continue;
}
let inner_parts: Vec<&str> = el.split(":").collect();
Expand Down
4 changes: 2 additions & 2 deletions leaf/src/config/conf/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ pub fn to_internal(conf: &mut Config) -> Result<internal::Config> {
for item in ext_always_real_ip {
fake_dns_exclude.push(item.clone())
}
if fake_dns_exclude.len() > 0 {
if !fake_dns_exclude.is_empty() {
settings.fake_dns_exclude = fake_dns_exclude;
}
}
Expand All @@ -807,7 +807,7 @@ pub fn to_internal(conf: &mut Config) -> Result<internal::Config> {
for item in ext_always_fake_ip {
fake_dns_include.push(item.clone())
}
if fake_dns_include.len() > 0 {
if !fake_dns_include.is_empty() {
settings.fake_dns_include = fake_dns_include;
}
}
Expand Down
6 changes: 3 additions & 3 deletions leaf/src/config/json/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ pub fn to_internal(json: &mut Config) -> Result<internal::Config> {
fake_dns_exclude.push(ext_exclude);
}
}
if fake_dns_exclude.len() > 0 {
if !fake_dns_exclude.is_empty() {
settings.fake_dns_exclude = fake_dns_exclude;
}

Expand All @@ -357,7 +357,7 @@ pub fn to_internal(json: &mut Config) -> Result<internal::Config> {
fake_dns_include.push(ext_include);
}
}
if fake_dns_include.len() > 0 {
if !fake_dns_include.is_empty() {
settings.fake_dns_include = fake_dns_include;
}

Expand Down Expand Up @@ -707,7 +707,7 @@ pub fn to_internal(json: &mut Config) -> Result<internal::Config> {
alpns.push(ext_alpn);
}
}
if alpns.len() > 0 {
if !alpns.is_empty() {
settings.alpn = alpns;
}
if let Some(ext_certificate) = ext_settings.certificate {
Expand Down
2 changes: 1 addition & 1 deletion leaf/src/proxy/tls/outbound/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Handler {
}
let mut builder =
SslConnector::builder(SslMethod::tls()).expect("create ssl connector failed");
if alpns.len() > 0 {
if !alpns.is_empty() {
let wire = alpns
.into_iter()
.map(|a| [&[a.len() as u8], a.as_bytes()].concat())
Expand Down

0 comments on commit ac323bc

Please sign in to comment.