From 59bea23004e112b9156ec219ad09308c7f7dbcde Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 26 Jun 2019 20:18:21 +0200 Subject: [PATCH] Simplify implementation of has_tag() Signed-off-by: Matthias Beyer --- lib/entry/libimagentrytag/src/tagable.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs index 267e57f4..c5968f4f 100644 --- a/lib/entry/libimagentrytag/src/tagable.rs +++ b/lib/entry/libimagentrytag/src/tagable.rs @@ -108,20 +108,8 @@ impl Tagable for Value { } fn has_tag(&self, t: TagSlice) -> Result { - let tags = self.read("tag.values").context(EM::EntryHeaderReadError)?; - - if !tags.iter().all(|t| is_match!(*t, &Value::String(_))) { - return Err(err_msg("Tag type error")) - } - - Ok(tags - .iter() - .any(|tag| { - match *tag { - &Value::String(ref s) => { s == t }, - _ => unreachable!() - } - })) + // use any() because Vec::contains() wants &String, but we do not want to allocate. + self.get_tags().map(|v| v.iter().any(|s| s == t)) } fn has_tags(&self, tags: &[Tag]) -> Result {