From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id DA47D628B0 for ; Thu, 17 Sep 2020 11:21:40 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CAAAEB75D for ; Thu, 17 Sep 2020 11:21:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id CB3C8B752 for ; Thu, 17 Sep 2020 11:21:06 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6BDBF45418 for ; Thu, 17 Sep 2020 11:21:06 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 17 Sep 2020 11:21:05 +0200 Message-Id: <20200917092105.17512-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.173 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs] Subject: [pbs-devel] [PATCH proxmox] api-macro: replace ident hashmap with simple find X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 09:21:40 -0000 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 --- 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, } 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 { @@ -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