This is an automated email from the ASF dual-hosted git repository.

Kriskras99 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 40390dd  perf: Optimize `Alias::new()` and 
`Parser::fix_aliases_namespace` (#557)
40390dd is described below

commit 40390dd92b64a401848f10d2fe1ad8200a632724
Author: Kriskras99 <[email protected]>
AuthorDate: Thu Jun 18 08:48:55 2026 +0200

    perf: Optimize `Alias::new()` and `Parser::fix_aliases_namespace` (#557)
---
 avro/src/schema/name.rs   | 11 ++++++++++-
 avro/src/schema/parser.rs | 11 ++---------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/avro/src/schema/name.rs b/avro/src/schema/name.rs
index 31a5f1e..aa22cee 100644
--- a/avro/src/schema/name.rs
+++ b/avro/src/schema/name.rs
@@ -257,15 +257,24 @@ impl<'de> Deserialize<'de> for Name {
 }
 
 /// Newtype pattern for `Name` to better control the `serde_json::Value` 
representation.
+///
 /// Aliases are serialized as an array of plain strings in the JSON 
representation.
 #[derive(Clone, Debug, Hash, PartialEq, Eq)]
 pub struct Alias(Name);
 
 impl Alias {
-    pub fn new(name: &str) -> AvroResult<Self> {
+    pub fn new(name: impl Into<String> + AsRef<str>) -> AvroResult<Self> {
         Name::new(name).map(Self)
     }
 
+    /// Create a new `Alias` using the namespace from `enclosing_namespace` if 
absent.
+    pub fn new_with_enclosing_namespace(
+        name: impl Into<String> + AsRef<str>,
+        enclosing_namespace: NamespaceRef,
+    ) -> AvroResult<Self> {
+        Name::new_with_enclosing_namespace(name, enclosing_namespace).map(Self)
+    }
+
     pub fn name(&self) -> &str {
         self.0.name()
     }
diff --git a/avro/src/schema/parser.rs b/avro/src/schema/parser.rs
index 57ef412..678d646 100644
--- a/avro/src/schema/parser.rs
+++ b/avro/src/schema/parser.rs
@@ -803,19 +803,12 @@ impl Parser {
         aliases
             .map(|aliases| {
                 aliases
-                    .iter()
+                    .into_iter()
                     .map(|alias| {
                         // An alias that is not a valid Avro name is a schema
                         // error — propagate it instead of unwrapping (which
                         // would panic on attacker-controlled schema JSON).
-                        if alias.contains('.') {
-                            Alias::new(alias.as_str())
-                        } else {
-                            match namespace {
-                                Some(ns) => 
Alias::new(&format!("{ns}.{alias}")),
-                                None => Alias::new(alias.as_str()),
-                            }
-                        }
+                        Alias::new_with_enclosing_namespace(alias, namespace)
                     })
                     .collect::<AvroResult<Vec<_>>>()
             })

Reply via email to