Skip to content
This repository
Browse code

sequences: better "halves".

  • Loading branch information...
commit deced177a85c58e972a94bad223ccaa380bf22e0 1 parent 43a4036
John Benediktsson authored September 04, 2012

Showing 1 changed file with 5 additions and 6 deletions. Show diff stats Hide diff stats

  1. 11  core/sequences/sequences.factor
11  core/sequences/sequences.factor
@@ -230,14 +230,12 @@ TUPLE: slice-error from to seq reason ;
230 230
 <PRIVATE
231 231
 
232 232
 : <slice-unsafe> ( from to seq -- slice )
233  
-    slice boa ; inline
  233
+    dup slice? [ collapse-slice ] when slice boa ; inline
234 234
 
235 235
 PRIVATE>
236 236
 
237 237
 : <slice> ( from to seq -- slice )
238  
-    check-slice
239  
-    dup slice? [ collapse-slice ] when
240  
-    <slice-unsafe> ; inline
  238
+    check-slice <slice-unsafe> ; inline
241 239
 
242 240
 M: slice virtual-exemplar seq>> ; inline
243 241
 
@@ -853,13 +851,14 @@ PRIVATE>
853 851
     ] if ;
854 852
 
855 853
 : cut-slice ( seq n -- before-slice after-slice )
856  
-    [ head-slice ] [ tail-slice ] 2bi ;
  854
+    [ head-slice ] [ tail-slice ] 2bi ; inline
857 855
 
858 856
 : insert-nth ( elt n seq -- seq' )
859 857
     swap cut-slice [ swap suffix ] dip append ;
860 858
 
861 859
 : halves ( seq -- first-slice second-slice )
862  
-    dup midpoint@ cut-slice ;
  860
+    [ 0 swap length [ 2/ dup ] keep ] keep
  861
+    [ <slice-unsafe> ] curry 2bi@ ; inline
863 862
 
864 863
 : binary-reduce ( ... seq start quot: ( ... elt1 elt2 -- ... newelt ) -- ... value )
865 864
     #! We can't use case here since combinators depends on

0 notes on commit deced17

Please sign in to comment.
Something went wrong with that request. Please try again.