Skip to content

Compute plural info once per PO file at compile time - #449

Merged
whatyouhide merged 1 commit into
elixir-gettext:mainfrom
oliver-kriska:plural-info-once
Oct 27, 2026
Merged

whatyouhide merged 1 commit into
elixir-gettext:mainfrom
oliver-kriska:plural-info-once

Conversation

@oliver-kriska

Copy link
Copy Markdown
Contributor

Call c:Gettext.Plural.init/1 once per PO file at compile time, as documented, instead of twice. Compute Plural.plural_info/3 once and pass the same value to both the plural-form compiler and nplurals/1. This also emits the deprecated nplurals-only header warning once rather than twice.

Split from #445 as requested, based directly on the latest upstream main. The rebase preserves the literal-map compilation added in #446. This PR does not depend on either of the other two split changes.

The implementation-detail CountingPlural test remains removed per José's review. The existing full suite passes: 193 checks (188 tests and 5 doctests) on Elixir 1.20.4/OTP 29 and 1.18.4/OTP 27, with compilation using --warnings-as-errors and formatting checked. All three split changes also combine without conflicts and pass together. No application-wide compile-time speedup is claimed.

`compile_po_file/5` derived the plural data twice: once in `nplurals/3` and
once in `compile_plural_forms/4`, each calling `Plural.plural_info/3`. That
function runs `Code.ensure_compiled!/1` and parses the `Plural-Forms` header,
so it is needless work repeated for every PO file across all locales and
domains.

Compute `plural_info` once in `compile_po_file/5` and pass it to both helpers.
The generated code is identical (the same value is escaped into the plural
dispatcher and fed to `nplurals/1`); only the duplicate computation is removed.
@whatyouhide

Copy link
Copy Markdown
Contributor

Thank you @oliver-kriska 🫶

@whatyouhide
whatyouhide merged commit 7a2b846 into elixir-gettext:main Oct 27, 2026
2 checks 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.

3 participants