Skip to content

Commit

Permalink
Remove dependency on List::MoreUtils
Browse files Browse the repository at this point in the history
Current LMU maintainer was proven unresponsive to concerns about the towering
complexity of that modules dependency chain. Use a pure-perl implementation
of uniq() compatible with the version in LMU 0.4xx series

The slowdown, while noticeable, is of no consequence to the larger codebase

~$ dd if=/dev/urandom bs=512 count=1 2>/dev/null | perl -0777 -Ilib -MSQL::Translator::Utils -MList::MoreUtils::XS -MBenchmark::Dumb -e '
  my @list = map ord, split "", <>;

  Benchmark::Dumb::cmpthese( 0.0001 => {
    lmu => sub {
      List::MoreUtils::uniq(@list);
    },
    pp => sub {
      SQL::Translator::Utils::uniq(@list);
    }
  })
'
               Rate    pp    lmu
pp  2838.17+-0.28/s    -- -35.2%
lmu 4381.99+-0.44/s 54.4%     --
  • Loading branch information
ribasushi committed Jun 24, 2015
1 parent c1f9a59 commit a1c9c64
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@ Changes for SQL::Translator

* Add support for monotonically increasing SQLite autoincs (GH#47)
* Declare dependencies in deterministic order (RT#102859)
* Remove dependency on List::MoreUtils ( http://is.gd/lmu_cac_debacle )

0.11021 2015-01-29

Expand Down
1 change: 0 additions & 1 deletion Makefile.PL
Expand Up @@ -18,7 +18,6 @@ my $deps = {
'Package::Variant' => '1.001001',
'Sub::Quote' => '0',
'Try::Tiny' => '0.04',
'List::MoreUtils' => '0.09',
'Scalar::Util' => '0',
},
recommends => {
Expand Down
3 changes: 1 addition & 2 deletions lib/SQL/Translator/Role/ListAttr.pm
Expand Up @@ -22,8 +22,7 @@ attributes.
=cut

use SQL::Translator::Utils qw(parse_list_arg ex2err);
use List::MoreUtils qw(uniq);
use SQL::Translator::Utils qw(parse_list_arg ex2err uniq);
use Sub::Quote qw(quote_sub);

use Package::Variant (
Expand Down
3 changes: 1 addition & 2 deletions lib/SQL/Translator/Schema/Trigger.pm
Expand Up @@ -29,9 +29,8 @@ C<SQL::Translator::Schema::Trigger> is the trigger object.
=cut

use Moo;
use SQL::Translator::Utils qw(parse_list_arg ex2err throw);
use SQL::Translator::Utils qw(parse_list_arg ex2err throw uniq);
use SQL::Translator::Types qw(schema_obj enum);
use List::MoreUtils qw(uniq);
use Sub::Quote qw(quote_sub);

extends 'SQL::Translator::Schema::Object';
Expand Down
11 changes: 10 additions & 1 deletion lib/SQL/Translator/Utils.pm
Expand Up @@ -16,7 +16,7 @@ our @EXPORT_OK = qw(
debug normalize_name header_comment parse_list_arg truncate_id_uniquely
$DEFAULT_COMMENT parse_mysql_version parse_dbms_version
ddl_parser_instance batch_alter_table_statements
throw ex2err carp_ro
uniq throw ex2err carp_ro
normalize_quote_options
);
use constant COLLISION_TAG_LENGTH => 8;
Expand Down Expand Up @@ -366,6 +366,15 @@ sub _find_co_root {
}
}

sub uniq {
my( %seen, $seen_undef, $numeric_preserving_copy );
grep { not (
defined $_
? $seen{ $numeric_preserving_copy = $_ }++
: $seen_undef++
) } @_;
}

sub throw {
die SQL::Translator::Utils::Error->new($_[0]);
}
Expand Down

0 comments on commit a1c9c64

Please sign in to comment.