commit: b08a61c8a47957854d91140eb7d8e9fba4290106
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Jan 9 08:17:21 2026 +0000
Commit: Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Fri Jan 9 08:17:21 2026 +0000
URL: https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=b08a61c8
Optimise the render_printable() subroutine
It used to be that the render_printable() subroutine would be called no
more than once before locale-gen(8) exits. However, this is no longer
the case.
Have the subroutine enclose a persistent JSON::PP object rather than
instantiate it every single time. Doing so improves performance by
approximately 17% across multiple calls.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
locale-gen | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/locale-gen b/locale-gen
index 8ae8a47..62a6149 100644
--- a/locale-gen
+++ b/locale-gen
@@ -679,7 +679,8 @@ sub plural ($int) {
sub render_printable ($value) {
require JSON::PP;
- return JSON::PP->new->ascii->space_after->encode($value)
+ state $coder = JSON::PP->new->ascii->space_after;
+ return $coder->encode($value)
}
sub run ($cmd, @args) {