Commit af66bf2400 for openssl.org
commit af66bf2400d4fe438136cf63aae10d3fbf6bec30
Author: Paul Dale <paul.dale@oracle.com>
Date: Mon Nov 16 11:58:15 2026 +1100
params: merge common param suffixes
Reuse parameter name endings. This reduces the name array from 4293
to 3995 bytes.
A brute force algorithm is used. If this becomes a problem, something
more sophisticated could be implemented.
Assisted-by: ChatGPT:gpt-6-Sol
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Merge-date: Tue Nov 24 21:10:15 2026
Merged-from: https://github.com/openssl/openssl/pull/33655
diff --git a/util/perl/OpenSSL/paramnames.pm b/util/perl/OpenSSL/paramnames.pm
index f342db224f..41f868a25a 100644
--- a/util/perl/OpenSSL/paramnames.pm
+++ b/util/perl/OpenSSL/paramnames.pm
@@ -709,6 +709,7 @@ sub output_endifdef {
sub calculate_name_offsets {
my %offsets = ();
my %name_positions = ();
+ my %resolved_names = ();
my $character_count = 0;
foreach my $name (sort keys %params) {
@@ -719,6 +720,16 @@ sub calculate_name_offsets {
$param_text = $params{substr($param_text, 1)};
}
+ $resolved_names{$name} = $param_text;
+ }
+
+ # Store longer names first so shorter names can share their suffixes.
+ foreach my $name (sort {
+ length($resolved_names{$b}) <=> length($resolved_names{$a})
+ || $a cmp $b
+ } keys %params) {
+ my $param_text = $resolved_names{$name};
+
# Assume we're creating a new record
my %offset = (
name => $name,
@@ -730,7 +741,12 @@ sub calculate_name_offsets {
$offset{"position"} = $name_positions{$param_text};
$offset{"dup"} = 1;
} else {
- $name_positions{$param_text} = $character_count;
+ # Check if the string exists as a suffix of another existing string.
+ # This is a brute force implementation, if it becomes an issue
+ # something more elegant should be implemented.
+ for my $i (0 .. length($param_text)) {
+ $name_positions{substr($param_text, $i)} //= $character_count + $i;
+ }
$character_count += length($param_text) + 1;
}
$offsets{$name} = \%offset;
@@ -769,7 +785,10 @@ sub generate_param_name_array {
my @name_text = ();
my ($total, %position_info) = calculate_name_offsets();
- foreach my $name (sort keys %params) {
+ foreach my $name (sort {
+ $position_info{$a}{'position'} <=> $position_info{$b}{'position'}
+ || $a cmp $b
+ } keys %params) {
my $val = $position_info{$name}{'text'};
my $text = '';