[darcs-devel] darcs patch: strip trailing CR in pref files
Will
will at glozer.net
Fri Dec 17 09:35:16 PST 2004
On Fri, 17 Dec 2004 08:53:24 -0500, "David Roundy"
<droundy at abridgegame.org> said:
> On Thu, Dec 16, 2004 at 03:10:47AM -0500, Will wrote:
> > Thu Dec 16 00:39:07 MST 2004 Will <will at glozer.net>
> > * strip trailing CR in pref files
>
> Thanks! I'll apply this momentarily. I just have a few comments on where
> the code could be nicer (which I won't implement myself).
Thanks, I'll submit a patch to clean this up.
> > + line <- getLine
> > + return $ stripCr line
>
> Here would be a good opportunity for liftM.
>
> > hunk ./DarcsUtils.lhs 59
> > +
> > +stripCr :: String -> String
> > +stripCr [] = []
> > +stripCr s = if s!!n == '\r' then (take n s) else s
> > + where n = (length s) - 1
>
> I think this is a bit less efficient than it need be. I'd do
>
> stripCr "" = ""
> stripCr "\r" = ""
> stripCr (c:cs) = c : stripCr cs
>
> This combines the O(N) length with the O(N) take and the O(N) !!. But on
> prefs files, it's not a big deal.
I'm glad you noticed, I was wondering whether GHC would optimize length
and !! to O(1) operations or not. My hope was to avoid the cost of
duplicating each line for the majority (I assume) of cases where there
are no CRs, any suggestions?
Regards,
Will
More information about the darcs-devel
mailing list