[darcs-users] darcs patch: change parseData in OldDate and IsoDate to use ByteStr...

Eric Kow kowey at darcs.net
Fri Apr 24 10:37:39 UTC 2009


On Fri, Apr 24, 2009 at 01:38:57 -0700, Benedikt Schmidt wrote:
> Fri Apr 24 10:33:17 CEST 2009  Benedikt Schmidt <beschmi at gmail.com>
>   * change parseData in OldDate and IsoDate to use ByteStrings
>   
>   This is a performance optimization to speed up patch
>   parsing and make_filename. The old version used naive
>   list code to parse the date (drop, take, and read). Just
>   using the more efficient ByteString versions makes the code
>   fast enough to not be a bottleneck.
 
Applied, thanks!

We try to be very careful about modifying the 'Old' modules because
we're afraid of breaking backward compatibility with older patches.  But
these look safe to me, and I'm reassured by review from Dmitry :-)

I was especially pleased that Dmitry took it upon himself to do
reviewing, because this means we avoid an extra email loop of me
assigning a patch, and everything just runs smoothly :-)

Thanks for the numbers too!

Eric

change parseData in OldDate and IsoDate to use ByteStrings
----------------------------------------------------------
> Benedikt Schmidt <beschmi at gmail.com>**20090424083317
>  Ignore-this: 1a629249eec23e8ada10be3d42065f57
>  
>  This is a performance optimization to speed up patch
>  parsing and make_filename. The old version used naive
>  list code to parse the date (drop, take, and read). Just
>  using the more efficient ByteString versions makes the code
>  fast enough to not be a bottleneck.
> ] hunk ./src/IsoDate.hs 36
>  import Data.Char ( toUpper, isDigit )
>  import Data.Maybe ( fromMaybe )
>  import Control.Monad ( liftM, liftM2 )
> +import qualified Data.ByteString.Char8 as B
>  
>  type TimeInterval = (Maybe CalendarTime, Maybe CalendarTime)
>  
> hunk ./src/IsoDate.hs 77
>  --   understood are those of 'showIsoDateTime' and 'date_time'
>  parseDate :: Int -> String -> Either ParseError MCalendarTime
>  parseDate tz d =
> -              if length d >= 14 && and (map isDigit $ take 14 d)
> +              if length d >= 14 && B.all isDigit bd
>                then Right $ toMCalendarTime $
> hunk ./src/IsoDate.hs 79
> -                   CalendarTime (read $ take 4 d)
> -                                (toEnum $ (+ (-1)) $ read $ take 2 $ drop 4 d)
> -                                (read $ take 2 $ drop 6 d) -- Day
> -                                (read $ take 2 $ drop 8 d) -- Hour
> -                                (read $ take 2 $ drop 10 d) -- Minute
> -                                (read $ take 2 $ drop 12 d) -- Second
> +                   CalendarTime (readI $ B.take 4 bd)
> +                                (toEnum $ (+ (-1)) $ readI $ B.take 2 $ B.drop 4 bd)
> +                                (readI $ B.take 2 $ B.drop 6 bd) -- Day
> +                                (readI $ B.take 2 $ B.drop 8 bd) -- Hour
> +                                (readI $ B.take 2 $ B.drop 10 bd) -- Minute
> +                                (readI $ B.take 2 $ B.drop 12 bd) -- Second
>                                  0 Sunday 0 -- Picosecond, weekday and day of year unknown
>                                  "GMT" 0 False
>                else let dt = do { x <- date_time tz; eof; return x }

> hunk ./src/IsoDate.hs 89
(same change made as to OldDate)

-- 
Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow>
PGP Key ID: 08AC04F9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.osuosl.org/pipermail/darcs-users/attachments/20090424/f40177a5/attachment.pgp>


More information about the darcs-users mailing list