diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-04-12 21:48:32 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-04-13 07:10:52 +0200 |
commit | d43faa89f16dd9a21fdd19034c24e6d113b7c219 (patch) | |
tree | c8136f86a0dfb1c2ace8cddb35e84ee6bacc0d59 | |
parent | 9232cafb6678160c3fe5154a7619a5e65c037a2b (diff) | |
download | askama-d43faa89f16dd9a21fdd19034c24e6d113b7c219.tar.gz askama-d43faa89f16dd9a21fdd19034c24e6d113b7c219.tar.bz2 askama-d43faa89f16dd9a21fdd19034c24e6d113b7c219.zip |
Eliminate common tails from branches
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/filters/mod.rs | 6 | ||||
-rw-r--r-- | askama_shared/src/generator.rs | 6 |
2 files changed, 4 insertions, 8 deletions
diff --git a/askama_shared/src/filters/mod.rs b/askama_shared/src/filters/mod.rs index ce87fd9..74486c0 100644 --- a/askama_shared/src/filters/mod.rs +++ b/askama_shared/src/filters/mod.rs @@ -256,17 +256,15 @@ pub fn trim<T: fmt::Display>(s: T) -> Result<String> { /// Limit string length, appends '...' if truncated pub fn truncate<T: fmt::Display>(s: T, len: usize) -> Result<String> { let mut s = s.to_string(); - if s.len() <= len { - Ok(s) - } else { + if s.len() > len { let mut real_len = len; while !s.is_char_boundary(real_len) { real_len += 1; } s.truncate(real_len); s.push_str("..."); - Ok(s) } + Ok(s) } /// Indent lines with `width` spaces diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index e6a890e..b5ab31c 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -1453,12 +1453,10 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { args: &[Expr], ) -> Result<DisplayWrap, CompileError> { buf.write("("); - if self.locals.contains(&s) || s == "self" { - buf.write(s); - } else { + if !self.locals.contains(&s) && s != "self" { buf.write("self."); - buf.write(s); } + buf.write(s); buf.write(")("); self._visit_args(buf, args)?; buf.write(")"); |