From c1994342e0c039fd9233f64855d6516935227896 Mon Sep 17 00:00:00 2001 From: simonpj Date: Thu, 7 Sep 2000 09:10:07 +0000 Subject: [PATCH] [project @ 2000-09-07 09:10:07 by simonpj] * Make the desugarer use string equality for string literal patterns longer than 1 character. And put a specialised eqString into PrelBase, with a suitable specialisation rule. This makes a huge difference to the size of the code generated by deriving(Read) notably in Time.lhs --- ghc/compiler/deSugar/DsUtils.lhs | 7 ++----- ghc/lib/std/PrelBase.lhs | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ghc/compiler/deSugar/DsUtils.lhs b/ghc/compiler/deSugar/DsUtils.lhs index bf63c5f..2221c26 100644 --- a/ghc/compiler/deSugar/DsUtils.lhs +++ b/ghc/compiler/deSugar/DsUtils.lhs @@ -92,7 +92,7 @@ tidyLitPat lit lit_ty default_pat | lit_ty == floatTy = ConPat floatDataCon lit_ty [] [] [LitPat (mk_float lit) floatPrimTy] | lit_ty == doubleTy = ConPat doubleDataCon lit_ty [] [] [LitPat (mk_double lit) doublePrimTy] - -- Convert literal patterns like "foo" to 'f':'o':'o':[] + -- Convert short string-literal patterns like "f" to 'f':[] | str_lit lit = mk_list lit | otherwise = default_pat @@ -116,10 +116,7 @@ tidyLitPat lit lit_ty default_pat mk_double (HsFrac f) = HsDoublePrim f mk_double l@(HsLitLit s) = l - null_str_lit (HsString s) = _NULL_ s - null_str_lit other_lit = False - - str_lit (HsString s) = True + str_lit (HsString s) = _LENGTH_ s <= 1 -- Short string literals only str_lit _ = False mk_list (HsString s) = foldr diff --git a/ghc/lib/std/PrelBase.lhs b/ghc/lib/std/PrelBase.lhs index cebd110..315469d 100644 --- a/ghc/lib/std/PrelBase.lhs +++ b/ghc/lib/std/PrelBase.lhs @@ -1,5 +1,5 @@ % ----------------------------------------------------------------------------- -% $Id: PrelBase.lhs,v 1.36 2000/08/29 17:42:17 qrczak Exp $ +% $Id: PrelBase.lhs,v 1.37 2000/09/07 09:10:07 simonpj Exp $ % % (c) The University of Glasgow, 1992-2000 % @@ -108,14 +108,14 @@ default () -- Double isn't available yet %********************************************************* \begin{code} -{- +{- data Bool = False | True data Ordering = LT | EQ | GT data Char = C# Char# type String = [Char] data Int = I# Int# data () = () --- data [] a = MkNil +data [] a = MkNil not True = False (&&) True True = True @@ -195,7 +195,6 @@ class Monad m where m >> k = m >>= \_ -> k fail s = error s - \end{code} @@ -454,6 +453,20 @@ ord :: Char -> Int ord (C# c) = I# (ord# c) \end{code} +String equality is used when desugaring pattern-matches against strings. +It's worth making it fast, and providing a rule to use the fast version +where possible. + +\begin{code} +eqString :: String -> String -> Bool +eqString [] [] = True +eqString (C# c1 : cs1) (C# c2 : cs2) = c1 `eqChar#` c2 && cs1 `eqString` cs2 +eqString _ _ = False + +{-# RULES +"eqString" (==) = eqString + #-} +\end{code} %********************************************************* %* * @@ -715,5 +728,4 @@ unpackNBytes# addr len# = unpack [] (len# -# 1#) -- unpackFoldr "foo" c (unpackFoldr "baz" c n) = unpackFoldr "foobaz" c n #-} - \end{code} -- 1.7.10.4