Skip to content

perf: avoid unnecessary error allocation in NthOr, NthOrEmpty - #817

Merged
samber merged 1 commit into
samber:masterfrom
d-enk:perf-nth
Feb 25, 2026
Merged

samber merged 1 commit into
samber:masterfrom
d-enk:perf-nth

Conversation

@d-enk

@d-enk d-enk commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Extract core logic into sliceNth/seqNth func returning (T, bool) instead of (T, error).

NthOr and NthOrEmpty now use these directly,
avoiding fmt.Errorf allocation when nth is out of bounds.

@d-enk
d-enk marked this pull request as draft February 24, 2026 19:07
@d-enk
d-enk marked this pull request as ready for review February 24, 2026 19:33
Extract core logic into sliceNth/seqNth func returning (T, bool) instead of (T, error).

NthOr and NthOrEmpty now use these directly,
avoiding fmt.Errorf allocation when nth is out of bounds.
@d-enk d-enk closed this Feb 24, 2026
@d-enk d-enk changed the title perf: eliminate error allocation in NthOr, NthOrEmpty perf: avoid unnecessary error allocation in NthOr, NthOrEmpty Feb 24, 2026
@d-enk d-enk reopened this Feb 24, 2026
@samber
samber merged commit b27b006 into samber:master Feb 25, 2026
1 check passed
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.

2 participants