@@ -383,10 +383,27 @@ data ChunkStreamState =
383383 [PosixPath ] -- files buffered
384384 Int -- file count
385385
386- -- XXX We can use a fold for collecting files and dirs.
387- -- A fold may be useful to translate the output to whatever format we want, we
388- -- can add a prefix or we can colorize it. The Right output would be the output
389- -- of the fold which can be any type not just a Path.
386+ -- XXX By using a fold we can unify readEitherChunks and readEitherByteChunks.
387+ -- For chunks we need to pass toList as the fold, and for ByteChunks we can
388+ -- pass a Fold m Path (Array Word). The Right output would be the output of the
389+ -- fold which can be any type not just a Path. The fold itself can perform
390+ -- transformations on the path e.g. colorization, filtering. In general we can
391+ -- use a (Path -> Maybe Path) function to do the transformations, for Path
392+ -- stream we can map it over the stream and for Folds we can use it to build
393+ -- the fold.
394+ --
395+ -- When using a fold compared to directly writing to an Array we have to make
396+ -- one more copy of each Path element to copy it from the readdir buffer
397+ -- (because it will go away) to a Path data type. However, the Path will be
398+ -- quickly written down to the Array while it is still hot in L1 cache, so
399+ -- there should not be much noticeable difference in perf.
400+ --
401+ -- Things that need to be controlled at the level of readdir and not after
402+ -- should be passed as readdir options e.g. maxDepth could be one such option
403+ -- because readdir has the visibility over it post-filtering would be
404+ -- inefficient. If we have to control it outside readdir we can efficiently
405+ -- control it by controlling the depth of the directories being fed back to
406+ -- concatIterate.
390407
391408-- XXX We can write a two fold scan to buffer and yield whichever fills first
392409-- like foldMany, it would be foldEither.
@@ -469,6 +486,7 @@ foreign import ccall unsafe "string.h memcpy" c_memcpy
469486foreign import ccall unsafe " string.h strlen" c_strlen
470487 :: Ptr CChar -> IO CSize
471488
489+ -- XXX Move this to common
472490-- Split a list in half.
473491splitHalf :: [a ] -> ([a ], [a ])
474492splitHalf xxs = split xxs xxs
0 commit comments