[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 15:04:41 UTC 2010


The following commit has been merged in the master branch:
commit e5b4ab2375eb30065c51b1095e96592d2156becc
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Dec 27 00:27:02 2005 +0100

    More efficient MissingH.List.contains courtesy Bulat Ziganshin

diff --git a/MissingH/List.hs b/MissingH/List.hs
index 94b809c..bc18448 100644
--- a/MissingH/List.hs
+++ b/MissingH/List.hs
@@ -55,10 +55,11 @@ module MissingH.List(-- * Tests
                      -- sub,
                     ) where
 import Data.List(intersperse, concat, isPrefixOf, isSuffixOf, elemIndices,
-                elemIndex, elemIndices)
+                elemIndex, elemIndices, tails, find)
 import IO
 import System.IO.Unsafe
 import Control.Monad.State(State, get, put)
+import Data.Maybe(isJust)
 
 {- | Returns true if the given list starts with the specified elements;
 false otherwise.  (This is an alias for "Data.List.isPrefixOf".)
@@ -179,14 +180,7 @@ Example:
 -}
 
 contains :: Eq a => [a] -> [a] -> Bool
-contains [] _ = True                    -- Sub is empty; matches anything
-contains _ [] = False                   -- List is empty; matches nothing
-contains sub searchlist =
-    let testlist = take (length sub) searchlist
-        in
-        case sub == testlist of
-                             True -> True
-                             False -> contains sub (tail searchlist)
+contains substr str = isJust $ find (isPrefixOf substr) (tails str)
 
 {- | Adds the specified (key, value) pair to the given list, removing any
 existing pair with the same key already present. -}

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list