Made untabify function tail recursive.
authorberghofe
Wed, 07 Feb 2007 12:05:54 +0100
changeset 22256 23f3ca04d3b3
parent 22255 8fcd11cb9be7
child 22257 159bfab776e2
Made untabify function tail recursive.
src/Pure/library.ML
--- a/src/Pure/library.ML	Tue Feb 06 19:32:32 2007 +0100
+++ b/src/Pure/library.ML	Wed Feb 07 12:05:54 2007 +0100
@@ -782,13 +782,14 @@
   let
     val tab_width = 8;
 
-    fun untab (_, "\n") = (0, ["\n"])
-      | untab (pos, "\t") =
-          let val d = tab_width - (pos mod tab_width) in (pos + d, replicate d " ") end
-      | untab (pos, c) = (pos + 1, [c]);
+    fun untab pos [] ys = rev ys 
+      | untab pos ("\n" :: xs) ys = untab 0 xs ("\n" :: ys)
+      | untab pos ("\t" :: xs) ys =
+          let val d = tab_width - (pos mod tab_width) in untab (pos + d) xs (replicate d " " @ ys) end
+      | untab pos (c :: xs) ys = untab (pos + 1) xs (c :: ys);
   in
     if not (exists (fn c => c = "\t") chs) then chs
-    else flat (#2 (foldl_map untab (0, chs)))
+    else untab 0 chs []
   end;
 
 fun prefix prfx s = prfx ^ s;