Skip to content

feat!: Rework Name to be more performant#493

Merged
martin-g merged 3 commits intomainfrom
feat/name_rework
Mar 3, 2026
Merged

feat!: Rework Name to be more performant#493
martin-g merged 3 commits intomainfrom
feat/name_rework

Conversation

@Kriskras99
Copy link
Copy Markdown
Contributor

@Kriskras99 Kriskras99 commented Feb 28, 2026

This is achieved by:

  • Making Name one allocation instead of two
  • Returning references as much as possible to reduce cloning
    • .namespace() returns a NamespaceRef<'_> which is a Option<&'_ str>
    • fully_qualified_name returns a Cow<'_, Name> which reduces allocations when the name already has a namespace or there is enclosing namespace.
  • Allow efficient construction of the name when there is an enclosing namespace
  • Display and fullname(None) can now return the full name directly

This required changing the SchemaNameValidator trait which now needs to return the index of the starting byte of the name. Included in this change is providing default implementations for *Validator::validate functions. This allows users to easily implement the trait by just returning a different regex.

Fixes #492

@Kriskras99 Kriskras99 changed the title feat: Rework Name to be more performant feat!: Rework Name to be more performant Mar 1, 2026
Comment thread avro/src/validator.rs
Comment thread avro/src/schema/name.rs
Comment thread avro/src/schema/name.rs
@martin-g martin-g added this to the 0.22.0 milestone Mar 3, 2026
Comment thread avro/src/error.rs Outdated
Kriskras99 and others added 3 commits March 3, 2026 12:09
This is achieved by:
- Making `Name` one allocation instead of two
- Returning references as much as possible to reduce cloning
  - `.namespace()` returns a `NamespaceRef<'_>` which is a `Option<&'_ str>`
  - `fully_qualified_name` returns a `Cow<'_, Name>` which reduces allocations
    when the name already has a namespace or there is enclosing namespace.
- Allow efficient construction of the name when there is an enclosing namespace
- `Display` and `fullname(None)` can now return the full name directly

This required changing the `SchemaNameValidator` trait which now needs to return
the index of the starting byte of the name. Included in this change is providing
default implementations for `*Validator::validate` functions. This allows users to
easily implement the trait by just returning a different regex.
Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
@martin-g martin-g merged commit 9dba371 into main Mar 3, 2026
21 checks passed
@martin-g martin-g deleted the feat/name_rework branch March 3, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why do the *Validator traits have the regex function?

2 participants