From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox] api-macro: replace ident hashmap with simple find
Date: Thu, 17 Sep 2020 11:21:05 +0200 [thread overview]
Message-ID: <20200917092105.17512-1-d.csapak@proxmox.com> (raw)
after benchmarking (again), i found that doing a simple find instead
of saving the inidices for the ident strings in a hashmap has
no real performance impact (the max list size for the properties
are max ~25 at the moment, so this should not be impacting compile
times much) but it is much simpler
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
proxmox-api-macro/src/api/mod.rs | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/proxmox-api-macro/src/api/mod.rs b/proxmox-api-macro/src/api/mod.rs
index 0071e81..1c2d0f7 100644
--- a/proxmox-api-macro/src/api/mod.rs
+++ b/proxmox-api-macro/src/api/mod.rs
@@ -8,7 +8,6 @@
//! The handling of methods vs type definitions happens in their corresponding submodules.
use std::convert::{TryFrom, TryInto};
-use std::collections::HashMap;
use anyhow::Error;
@@ -379,14 +378,12 @@ impl SchemaItem {
/// Contains a sorted list of properties:
pub struct SchemaObject {
properties_: Vec<(FieldName, bool, Schema)>,
- ident_hash: HashMap<String, usize>,
}
impl SchemaObject {
pub fn new() -> Self {
Self {
properties_: Vec::new(),
- ident_hash: HashMap::new(),
}
}
@@ -397,9 +394,6 @@ impl SchemaObject {
fn sort_properties(&mut self) {
self.properties_.sort_by(|a, b| (a.0).cmp(&b.0));
- for (idx, prop) in self.properties_.iter().enumerate() {
- self.ident_hash.insert(prop.0.as_ident_str().to_string(), idx);
- }
}
fn try_extract_from(obj: &mut JSONObject) -> Result<Self, syn::Error> {
@@ -428,7 +422,6 @@ impl SchemaObject {
Ok(properties)
},
)?,
- ident_hash: HashMap::new(),
};
this.sort_properties();
Ok(this)
@@ -446,17 +439,11 @@ impl SchemaObject {
}
fn find_property_by_ident(&self, key: &str) -> Option<&(FieldName, bool, Schema)> {
- match self.ident_hash.get(key) {
- Some(idx) => Some(&self.properties_[*idx]),
- None => None,
- }
+ self.properties_.iter().find(|p| p.0.as_ident_str() == key)
}
fn find_property_by_ident_mut(&mut self, key: &str) -> Option<&mut (FieldName, bool, Schema)> {
- match self.ident_hash.get(key) {
- Some(idx) => Some(&mut self.properties_[*idx]),
- None => None,
- }
+ self.properties_.iter_mut().find(|p| p.0.as_ident_str() == key)
}
fn extend_properties(&mut self, new_fields: Vec<(FieldName, bool, Schema)>) {
--
2.20.1
next reply other threads:[~2020-09-17 9:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-17 9:21 Dominik Csapak [this message]
2020-09-19 4:38 ` [pbs-devel] applied: " Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200917092105.17512-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox