develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33895 - trunk/languages/perl6/src/classes

From:
pmichaud
Date:
December 14, 2008 10:02
Subject:
[svn:parrot] r33895 - trunk/languages/perl6/src/classes
Message ID:
20081214180235.93494CBA12@x12.develooper.com
Author: pmichaud
Date: Sun Dec 14 10:02:34 2008
New Revision: 33895

Modified:
   trunk/languages/perl6/src/classes/Array.pir
   trunk/languages/perl6/src/classes/List.pir

Log:
[rakudo]:  Clean up flattening a fair bit.
This removes 15 seconds from "make spectest" on my machine,
and eliminates the special-case 'isa' checks from !flatten.


Modified: trunk/languages/perl6/src/classes/Array.pir
==============================================================================
--- trunk/languages/perl6/src/classes/Array.pir	(original)
+++ trunk/languages/perl6/src/classes/Array.pir	Sun Dec 14 10:02:34 2008
@@ -200,6 +200,7 @@
     .tailcall values.'Scalar'()
 .end
 
+
 =back
 
 =head2 Coercion methods
@@ -214,6 +215,25 @@
     .return (self)
 .end
 
+
+=back
+
+=head2 Private Methods
+
+=over
+
+=item !flatten()
+
+Return self, as Arrays are already flattened.
+
+=cut
+
+.namespace ['Perl6Array']
+.sub '!flatten' :method
+    .return (self)
+.end
+
+
 =back
 
 =cut

Modified: trunk/languages/perl6/src/classes/List.pir
==============================================================================
--- trunk/languages/perl6/src/classes/List.pir	(original)
+++ trunk/languages/perl6/src/classes/List.pir	Sun Dec 14 10:02:34 2008
@@ -236,22 +236,19 @@
   no_deref:
     $I0 = isa elem, 'ObjectRef'
     if $I0 goto flat_next
-    $I0 = isa elem, 'Range'
-    unless $I0 goto not_range
-    elem = elem.'list'()
-  not_range:
-    $I0 = isa elem, 'IOIterator'
-    unless $I0 goto not_ioiterator
-    elem = elem.'list'()
-  not_ioiterator:
+    $I0 = can elem, '!flatten'
+    if $I0 goto flat_elem
     $I0 = does elem, 'array'
-    unless $I0 goto flat_next
-    splice self, elem, i, 1
-    len = elements self
-    goto flat_loop
+    if $I0 goto flat_splice
   flat_next:
     inc i
     goto flat_loop
+  flat_elem:
+    elem = elem.'!flatten'()
+  flat_splice:
+    splice self, elem, i, 1
+    len = elements self
+    goto flat_loop
   flat_end:
     $I0 = isa self, 'List'
     if $I0 goto end



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About