# -------------------------------------------------------------------
sub next_unused_name {
- my $name = shift || '';
- if ( !defined( $used_names{$name} ) ) {
- $used_names{$name} = $name;
- return $name;
- }
+ my $orig_name = shift or return;
+ my $name = $orig_name;
+
+ my $suffix_gen = sub {
+ my $suffix = 0;
+ return ++$suffix ? '' : $suffix;
+ };
- my $i = 2;
- while ( defined( $used_names{ $name . $i } ) ) {
- ++$i;
+ for (;;) {
+ $name = $orig_name . $suffix_gen->();
+ last if $used_names{ $name }++;
}
- $name .= $i;
- $used_names{$name} = $name;
+
return $name;
}
-
sub create_table
{
my ($table, $options) = @_;