Skip to content

Commit df2eb9d

Browse files
authored
Merge pull request #1298 from dlglin/uniq-preserve-order
Rewrite the PG uniq function to return the array in a consistent order
2 parents 3f1164e + 96590b8 commit df2eb9d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

macros/core/PGbasicmacros.pl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,13 +2634,9 @@ =head2 Sorting and other list macros
26342634

26352635
# uniq gives unique elements of a list:
26362636
sub uniq {
2637-
my @in = @_;
2638-
my %temp = ();
2639-
while (@in) {
2640-
$temp{ shift(@in) }++;
2641-
}
2642-
my @out = keys %temp; # sort is causing trouble with Safe.??
2643-
@out;
2637+
my @in = @_;
2638+
my %seen;
2639+
return grep { !$seen{$_}++ } @in;
26442640
}
26452641

26462642
sub lex_sort {

0 commit comments

Comments
 (0)