From 8782a6250c968fcf3cf1e9f07ca75faeed7c441b Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Mon, 26 Aug 2024 22:19:00 +0900 Subject: [PATCH] :recycle: inlinize `State` --- src/file_manager.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/file_manager.rs b/src/file_manager.rs index 4fc8161..2383421 100644 --- a/src/file_manager.rs +++ b/src/file_manager.rs @@ -22,23 +22,21 @@ pub(crate) struct UnprocessedEntry { option: ReadOptions, } -pub(crate) enum State { +pub(crate) enum Entry { Loaded(LoadedEntry), Unprocessed(UnprocessedEntry), } -pub(crate) struct Entry(State); - impl Entry { fn empty() -> Self { - Self(State::Loaded(LoadedEntry { + Self::Loaded(LoadedEntry { data: Vec::new(), xattrs: HashMap::new(), - })) + }) } fn load(&mut self) -> &LoadedEntry { - if let State::Unprocessed(e) = &self.0 { + if let Self::Unprocessed(e) = &self { let mut xattrs = HashMap::with_capacity(e.entry.xattrs().len()); for xattr in e.entry.xattrs() { xattrs.insert(xattr.name().into(), xattr.value().into()); @@ -46,11 +44,11 @@ impl Entry { let mut buf = Vec::new(); let mut reader = e.entry.reader(e.option.clone()).unwrap(); reader.read_to_end(&mut buf).unwrap(); - self.0 = State::Loaded(LoadedEntry { data: buf, xattrs }); + *self = Self::Loaded(LoadedEntry { data: buf, xattrs }); } - match &self.0 { - State::Loaded(l) => l, - State::Unprocessed(_) => unreachable!(), + match self { + Self::Loaded(l) => l, + Self::Unprocessed(_) => unreachable!(), } } @@ -150,10 +148,10 @@ impl File { }; let option = ReadOptions::with_password(password); let (data, raw_size) = if let Some(raw_size) = metadata.raw_file_size() { - let data = Entry(State::Unprocessed(UnprocessedEntry { entry, option })); + let data = Entry::Unprocessed(UnprocessedEntry { entry, option }); (data, raw_size as usize) } else { - let mut data = Entry(State::Unprocessed(UnprocessedEntry { entry, option })); + let mut data = Entry::Unprocessed(UnprocessedEntry { entry, option }); let raw_size = data.as_slice().len(); (data, raw_size) };