Commits

Bryan O'Sullivan committed 4c1602f

Fix the definition of reverse

  • Participants
  • Parent commits d7dc6d4

Comments (0)

Files changed (2)

File Data/Text/Fusion.hs

         loop !s0 !i = case next s0 of
                         Done       -> return marr
                         Skip s1    -> loop s1 i
-                        Yield x s1 -> do
-                          let i' = i - 1
-                              x' = fromIntegral (ord x) :: Word16
-                          A.unsafeWrite marr i' x'
-                          loop s1 i'
+                        Yield x s1
+                            | n < 0x10000 -> do
+                                     let i' = i - 1
+                                     A.unsafeWrite marr i' (fromIntegral n)
+                                     loop s1 i'
+                            | otherwise -> do
+                                     let i' = i - 2
+                                     A.unsafeWrite marr i'     l
+                                     A.unsafeWrite marr (i'+1) r
+                                     loop s1 i'
+                            where n = ord x
+                                  m = n - 0x10000
+                                  l = fromIntegral $ (m `shiftR` 10) + 0xD800
+                                  r = fromIntegral $ (m .&. 0x3FF) + 0xDC00
 {-# INLINE [0] reverse #-}
 
 -- ----------------------------------------------------------------------------

File tests/Properties.hs

   ("prop_intercalate", mytest prop_intercalate),
   ("prop_intersperse", mytest prop_intersperse),
   ("prop_transpose", mytest prop_transpose),
---("prop_reverse", mytest prop_reverse),
+  ("prop_reverse", mytest prop_reverse),
 
   ("prop_foldl", mytest prop_foldl),
   ("prop_foldl'", mytest prop_foldl'),