On Tue May 20 23:20:41 2008, bacek wrote:

> There is another implementation based on FixedPMCArray.

Reworked version of patch after Jonathan review of old one.

-- 
Bacek
Index: src/classes/List.pir
===================================================================
--- src/classes/List.pir	(revision 27698)
+++ src/classes/List.pir	(working copy)
@@ -633,6 +633,58 @@
 
 =back
 
+=item !sort()
+
+Sort list by copying into FPA, sorting and creating new List.
+
+=cut
+
+.sub '!sort' :method
+    .param pmc comparer
+    .local pmc elem, arr, comparer
+    .local int len, i
+
+    # Creating FPA
+    arr = new 'FixedPMCArray'
+    len = elements self
+    arr = len
+
+    # Copy all elements into it
+    i = 0
+  copy_to:
+    if i == len goto done_to
+    elem = self[i]
+    arr[i] = elem
+    inc i
+    goto copy_to
+
+  done_to:
+
+    # Sort in-place
+    arr.'sort'(comparer)
+
+    # and return new List.
+    .return 'list'(arr)
+.end
+
+=head2 sort() 
+
+Sort list in-place
+
+=cut
+
+.sub 'sort' :method
+    .local pmc comparer
+    .local pmc res
+    
+    get_hll_global comparer, 'infix:leg'
+    res = self.'!sort'(comparer)
+
+    .return (res)
+.end
+
+
+
 =head1 Functions
 
 =over 4
@@ -668,6 +720,36 @@
 .end
 
 
+=item C<sort>
+
+Sort arguments.
+
+=cut
+
+.sub 'sort' :multi(_)
+    .param pmc args :slurpy
+    .local pmc l
+    
+    l = 'list'(args :flat)
+    .return l.'sort'()
+.end
+
+=item C<sort>
+
+Sort arguments using comparition sub.
+
+=cut
+
+.sub 'sort' :multi(_,_)
+    .param pmc comparer
+    .param pmc args :slurpy
+    .local pmc l
+    
+    l = 'list'(args :flat)
+    .return l.'!sort'(comparer)
+.end
+
+
 =item C<infix:,(...)>
 
 Operator form for building a list from its arguments.

Reply via email to