New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'@foo = sort { $a <=> $b } @bar' uses too much memory #7933
Comments
From @salvaCreated by salva@cabo.nonet@sorted = sort { $a <=> $b } @data; uses almost twice as memory as @sorted = sort { -($a <=> $b) } @data; for instance on my linux box: $ perl -e 'my @f=sort { -($a <=> $b) } ((1, 2) x 100000); VmSize: 9836 kB $ perl -e 'my @f=sort { $a <=> $b } ((1, 2) x 100000); VmSize: 17096 kB I have tested it also with other data (randomly generated, all terms Cheers, - Salvador Perl Info
|
From @salva
The difference in memory usage in pp_sort is caused by elements This is wrong for numerical comparisons that doesn't require its BTW, I think that there is another bug on pp_sort: when Cheers, - Salvador |
From @salvansort-0.01.patch--- perl-current/pp_sort.c 2005-06-02 09:07:41.000000000 +0100
+++ my-perl-current/pp_sort.c 2005-06-05 02:44:53.102721744 +0100
@@ -1593,17 +1593,40 @@
sortsvp = S_sortsv_desc;
}
- /* shuffle stack down, removing optional initial cv (p1!=p2), plus any
- * nulls; also stringify any args */
+ /* shuffle stack down, removing optional initial cv (p1!=p2), plus
+ * any nulls; also stringify or converting to integer or number as
+ * required any args */
for (i=max; i > 0 ; i--) {
if ((*p1 = *p2++)) { /* Weed out nulls. */
SvTEMP_off(*p1);
- if (!PL_sortcop && !SvPOK(*p1)) {
- STRLEN n_a;
- if (SvAMAGIC(*p1))
- overloading = 1;
- else
- (void)sv_2pv(*p1, &n_a);
+ if (!PL_sortcop) {
+ if (priv & OPpSORT_NUMERIC) {
+ if (priv & OPpSORT_INTEGER) {
+ if (!SvIOK(*p1)) {
+ if (SvAMAGIC(*p1))
+ overloading = 1;
+ else
+ (void)sv_2iv(*p1);
+ }
+ }
+ else {
+ if (!SvNOK(*p1)) {
+ if (SvAMAGIC(*p1))
+ overloading = 1;
+ else
+ (void)sv_2nv(*p1);
+ }
+ }
+ }
+ else {
+ if (!SvPOK(*p1)) {
+ STRLEN n_a;
+ if (SvAMAGIC(*p1))
+ overloading = 1;
+ else
+ (void)sv_2pv(*p1, &n_a);
+ }
+ }
}
p1++;
}
|
From @rgarciaOn 6/5/05, Salvador Fandiño <sfandino@yahoo.com> wrote:
Thanks, applied to bleadperl as change 24708. This should be suitable
That's probable... care to submit a patch ? (I see that it's quite |
The RT System itself - Status changed from 'new' to 'open' |
From @rgsFixed by : Change 24708 on 2005/06/05 by rgs@marais Subject: PATCH for [perl #36043] '@foo = sort { $a <=> $b } |
@rgs - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#36043 (status was 'resolved')
Searchable as RT36043$
The text was updated successfully, but these errors were encountered: